<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Math::BigInt - Arbitrary size integer/float math package - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/Math::BigInt">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Math::BigInt.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/Math::BigInt">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/Math::BigInt">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/Math::BigInt">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/Math::BigInt">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/Math::BigInt">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/Math::BigInt">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/Math::BigInt">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/Math::BigInt">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/Math::BigInt">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/Math::BigInt">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/Math::BigInt">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/Math::BigInt">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/Math::BigInt">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/Math::BigInt">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/Math::BigInt">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/Math::BigInt">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/Math::BigInt">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/Math::BigInt">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/Math::BigInt">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/Math::BigInt">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/Math::BigInt">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/Math::BigInt">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/Math::BigInt">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/Math::BigInt">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/Math::BigInt">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/Math::BigInt">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/Math::BigInt">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/Math::BigInt">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/Math::BigInt">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/Math::BigInt">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/Math::BigInt">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/Math::BigInt">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/Math::BigInt">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/Math::BigInt">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/Math::BigInt">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/Math::BigInt">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/Math::BigInt">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/Math::BigInt">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/Math::BigInt">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/Math::BigInt">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/Math::BigInt">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/Math::BigInt">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/Math::BigInt">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/Math::BigInt">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/Math::BigInt">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/Math::BigInt">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/Math::BigInt">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/Math::BigInt">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/Math::BigInt">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/Math::BigInt">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/Math::BigInt">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/Math::BigInt">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/Math::BigInt">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/Math::BigInt">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/Math::BigInt">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/Math::BigInt">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/Math::BigInt">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/Math::BigInt">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/Math::BigInt">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/Math::BigInt">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/Math::BigInt">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/Math::BigInt">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/Math::BigInt">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/Math::BigInt">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/Math::BigInt">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/Math::BigInt">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/Math::BigInt">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/Math::BigInt">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/Math::BigInt">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/Math::BigInt">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/Math::BigInt">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/Math::BigInt">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/Math::BigInt">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/Math::BigInt">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/Math::BigInt">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/Math::BigInt">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/Math::BigInt">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/Math::BigInt">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/Math::BigInt">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/Math::BigInt">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Math::BigInt.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/Math::BigInt">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/Math::BigInt">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/Math::BigInt">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/Math::BigInt">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/Math::BigInt">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/Math::BigInt">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/Math::BigInt">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/Math::BigInt">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/Math::BigInt">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/Math::BigInt">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/Math::BigInt">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/Math::BigInt">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/Math::BigInt">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/Math::BigInt">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/Math::BigInt">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/Math::BigInt">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/Math::BigInt">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/Math::BigInt">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/Math::BigInt">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/Math::BigInt">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/Math::BigInt">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/Math::BigInt">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/Math::BigInt">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/Math::BigInt">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/Math::BigInt">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/Math::BigInt">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/Math::BigInt">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/Math::BigInt">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/Math::BigInt">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/Math::BigInt">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/Math::BigInt">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/Math::BigInt">5.35.1</a>
          <a class="dropdown-item active" href="./Math::BigInt.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Math::BigInt.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./Math::BigInt.html">Math::BigInt</a>
          <div id="more">
            (<a href="./Math::BigInt.txt">source</a>,
            <a href="https://metacpan.org/pod/Math::BigInt">CPAN</a>)
          </div>
            <div id="moduleversion">version 1.999818</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Input">Input</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Output">Output</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#METHODS">METHODS</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Configuration-methods">Configuration methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Constructor-methods">Constructor methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Boolean-methods">Boolean methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Comparison-methods">Comparison methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Arithmetic-methods">Arithmetic methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Bitwise-methods">Bitwise methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Rounding-methods">Rounding methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Other-mathematical-methods">Other mathematical methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Object-property-methods">Object property methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#String-conversion-methods">String conversion methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Other-conversion-methods">Other conversion methods</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#ACCURACY-and-PRECISION">ACCURACY and PRECISION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Precision-P">Precision P</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Accuracy-A">Accuracy A</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Fallback-F">Fallback F</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Rounding-mode-R">Rounding mode R</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Directed-rounding">Directed rounding</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Rounding-to-nearest">Rounding to nearest</a>
              </li>
          </ul>

              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Infinity-and-Not-a-Number">Infinity and Not a Number</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#INTERNALS">INTERNALS</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#MATH-LIBRARY">MATH LIBRARY</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#What-library-to-use?">What library to use?</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#SIGN">SIGN</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#EXAMPLES">EXAMPLES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Autocreating-constants">Autocreating constants</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#PERFORMANCE">PERFORMANCE</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Alternative-math-libraries">Alternative math libraries</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#SUBCLASSING">SUBCLASSING</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Subclassing-Math::BigInt">Subclassing Math::BigInt</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#UPGRADING">UPGRADING</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#Auto-upgrade">Auto-upgrade</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#EXPORTS">EXPORTS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#CAVEATS">CAVEATS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#BUGS">BUGS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#SUPPORT">SUPPORT</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#LICENSE">LICENSE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Math::BigInt.html#AUTHORS">AUTHORS</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./Math::BigInt.html#NAME">#</a>NAME</h1>

<p>Math::BigInt - Arbitrary size integer/float math package</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./Math::BigInt.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code class="nohighlight">use Math::BigInt;

# or make it faster with huge numbers: install (optional)
# Math::BigInt::GMP and always use (it falls back to
# pure Perl if the GMP library is not installed):
# (See also the L&lt;MATH LIBRARY&gt; section!)

# warns if Math::BigInt::GMP cannot be found
use Math::BigInt lib =&gt; &#39;GMP&#39;;

# to suppress the warning use this:
# use Math::BigInt try =&gt; &#39;GMP&#39;;

# dies if GMP cannot be loaded:
# use Math::BigInt only =&gt; &#39;GMP&#39;;

my $str = &#39;1234567890&#39;;
my @values = (64, 74, 18);
my $n = 1; my $sign = &#39;-&#39;;

# Configuration methods (may be used as class methods and instance methods)

Math::BigInt-&gt;accuracy();     # get class accuracy
Math::BigInt-&gt;accuracy($n);   # set class accuracy
Math::BigInt-&gt;precision();    # get class precision
Math::BigInt-&gt;precision($n);  # set class precision
Math::BigInt-&gt;round_mode();   # get class rounding mode
Math::BigInt-&gt;round_mode($m); # set global round mode, must be one of
                              # &#39;even&#39;, &#39;odd&#39;, &#39;+inf&#39;, &#39;-inf&#39;, &#39;zero&#39;,
                              # &#39;trunc&#39;, or &#39;common&#39;
Math::BigInt-&gt;config();       # return hash with configuration

# Constructor methods (when the class methods below are used as instance
# methods, the value is assigned the invocand)

$x = Math::BigInt-&gt;new($str);             # defaults to 0
$x = Math::BigInt-&gt;new(&#39;0x123&#39;);          # from hexadecimal
$x = Math::BigInt-&gt;new(&#39;0b101&#39;);          # from binary
$x = Math::BigInt-&gt;from_hex(&#39;cafe&#39;);      # from hexadecimal
$x = Math::BigInt-&gt;from_oct(&#39;377&#39;);       # from octal
$x = Math::BigInt-&gt;from_bin(&#39;1101&#39;);      # from binary
$x = Math::BigInt-&gt;from_base(&#39;why&#39;, 36);  # from any base
$x = Math::BigInt-&gt;bzero();               # create a +0
$x = Math::BigInt-&gt;bone();                # create a +1
$x = Math::BigInt-&gt;bone(&#39;-&#39;);             # create a -1
$x = Math::BigInt-&gt;binf();                # create a +inf
$x = Math::BigInt-&gt;binf(&#39;-&#39;);             # create a -inf
$x = Math::BigInt-&gt;bnan();                # create a Not-A-Number
$x = Math::BigInt-&gt;bpi();                 # returns pi

$y = $x-&gt;copy();         # make a copy (unlike $y = $x)
$y = $x-&gt;as_int();       # return as a Math::BigInt

# Boolean methods (these don&#39;t modify the invocand)

$x-&gt;is_zero();          # if $x is 0
$x-&gt;is_one();           # if $x is +1
$x-&gt;is_one(&quot;+&quot;);        # ditto
$x-&gt;is_one(&quot;-&quot;);        # if $x is -1
$x-&gt;is_inf();           # if $x is +inf or -inf
$x-&gt;is_inf(&quot;+&quot;);        # if $x is +inf
$x-&gt;is_inf(&quot;-&quot;);        # if $x is -inf
$x-&gt;is_nan();           # if $x is NaN

$x-&gt;is_positive();      # if $x &gt; 0
$x-&gt;is_pos();           # ditto
$x-&gt;is_negative();      # if $x &lt; 0
$x-&gt;is_neg();           # ditto

$x-&gt;is_odd();           # if $x is odd
$x-&gt;is_even();          # if $x is even
$x-&gt;is_int();           # if $x is an integer

# Comparison methods

$x-&gt;bcmp($y);           # compare numbers (undef, &lt; 0, == 0, &gt; 0)
$x-&gt;bacmp($y);          # compare absolutely (undef, &lt; 0, == 0, &gt; 0)
$x-&gt;beq($y);            # true if and only if $x == $y
$x-&gt;bne($y);            # true if and only if $x != $y
$x-&gt;blt($y);            # true if and only if $x &lt; $y
$x-&gt;ble($y);            # true if and only if $x &lt;= $y
$x-&gt;bgt($y);            # true if and only if $x &gt; $y
$x-&gt;bge($y);            # true if and only if $x &gt;= $y

# Arithmetic methods

$x-&gt;bneg();             # negation
$x-&gt;babs();             # absolute value
$x-&gt;bsgn();             # sign function (-1, 0, 1, or NaN)
$x-&gt;bnorm();            # normalize (no-op)
$x-&gt;binc();             # increment $x by 1
$x-&gt;bdec();             # decrement $x by 1
$x-&gt;badd($y);           # addition (add $y to $x)
$x-&gt;bsub($y);           # subtraction (subtract $y from $x)
$x-&gt;bmul($y);           # multiplication (multiply $x by $y)
$x-&gt;bmuladd($y,$z);     # $x = $x * $y + $z
$x-&gt;bdiv($y);           # division (floored), set $x to quotient
                        # return (quo,rem) or quo if scalar
$x-&gt;btdiv($y);          # division (truncated), set $x to quotient
                        # return (quo,rem) or quo if scalar
$x-&gt;bmod($y);           # modulus (x % y)
$x-&gt;btmod($y);          # modulus (truncated)
$x-&gt;bmodinv($mod);      # modular multiplicative inverse
$x-&gt;bmodpow($y,$mod);   # modular exponentiation (($x ** $y) % $mod)
$x-&gt;bpow($y);           # power of arguments (x ** y)
$x-&gt;blog();             # logarithm of $x to base e (Euler&#39;s number)
$x-&gt;blog($base);        # logarithm of $x to base $base (e.g., base 2)
$x-&gt;bexp();             # calculate e ** $x where e is Euler&#39;s number
$x-&gt;bnok($y);           # x over y (binomial coefficient n over k)
$x-&gt;buparrow($n, $y);   # Knuth&#39;s up-arrow notation
$x-&gt;backermann($y);     # the Ackermann function
$x-&gt;bsin();             # sine
$x-&gt;bcos();             # cosine
$x-&gt;batan();            # inverse tangent
$x-&gt;batan2($y);         # two-argument inverse tangent
$x-&gt;bsqrt();            # calculate square root
$x-&gt;broot($y);          # $y&#39;th root of $x (e.g. $y == 3 =&gt; cubic root)
$x-&gt;bfac();             # factorial of $x (1*2*3*4*..$x)

$x-&gt;blsft($n);          # left shift $n places in base 2
$x-&gt;blsft($n,$b);       # left shift $n places in base $b
                        # returns (quo,rem) or quo (scalar context)
$x-&gt;brsft($n);          # right shift $n places in base 2
$x-&gt;brsft($n,$b);       # right shift $n places in base $b
                        # returns (quo,rem) or quo (scalar context)

# Bitwise methods

$x-&gt;band($y);           # bitwise and
$x-&gt;bior($y);           # bitwise inclusive or
$x-&gt;bxor($y);           # bitwise exclusive or
$x-&gt;bnot();             # bitwise not (two&#39;s complement)

# Rounding methods
$x-&gt;round($A,$P,$mode); # round to accuracy or precision using
                        # rounding mode $mode
$x-&gt;bround($n);         # accuracy: preserve $n digits
$x-&gt;bfround($n);        # $n &gt; 0: round to $nth digit left of dec. point
                        # $n &lt; 0: round to $nth digit right of dec. point
$x-&gt;bfloor();           # round towards minus infinity
$x-&gt;bceil();            # round towards plus infinity
$x-&gt;bint();             # round towards zero

# Other mathematical methods

$x-&gt;bgcd($y);            # greatest common divisor
$x-&gt;blcm($y);            # least common multiple

# Object property methods (do not modify the invocand)

$x-&gt;sign();              # the sign, either +, - or NaN
$x-&gt;digit($n);           # the nth digit, counting from the right
$x-&gt;digit(-$n);          # the nth digit, counting from the left
$x-&gt;length();            # return number of digits in number
($xl,$f) = $x-&gt;length(); # length of number and length of fraction
                         # part, latter is always 0 digits long
                         # for Math::BigInt objects
$x-&gt;mantissa();          # return (signed) mantissa as a Math::BigInt
$x-&gt;exponent();          # return exponent as a Math::BigInt
$x-&gt;parts();             # return (mantissa,exponent) as a Math::BigInt
$x-&gt;sparts();            # mantissa and exponent (as integers)
$x-&gt;nparts();            # mantissa and exponent (normalised)
$x-&gt;eparts();            # mantissa and exponent (engineering notation)
$x-&gt;dparts();            # integer and fraction part

# Conversion methods (do not modify the invocand)

$x-&gt;bstr();         # decimal notation, possibly zero padded
$x-&gt;bsstr();        # string in scientific notation with integers
$x-&gt;bnstr();        # string in normalized notation
$x-&gt;bestr();        # string in engineering notation
$x-&gt;bdstr();        # string in decimal notation

$x-&gt;to_hex();       # as signed hexadecimal string
$x-&gt;to_bin();       # as signed binary string
$x-&gt;to_oct();       # as signed octal string
$x-&gt;to_bytes();     # as byte string
$x-&gt;to_base($b);    # as string in any base

$x-&gt;as_hex();       # as signed hexadecimal string with prefixed 0x
$x-&gt;as_bin();       # as signed binary string with prefixed 0b
$x-&gt;as_oct();       # as signed octal string with prefixed 0

# Other conversion methods

$x-&gt;numify();           # return as scalar (might overflow or underflow)</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./Math::BigInt.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>Math::BigInt provides support for arbitrary precision integers. Overloading is also provided for Perl operators.</p>

<h2 id="Input"><a class="permalink" href="./Math::BigInt.html#Input">#</a>Input</h2>

<p>Input values to these routines may be any scalar number or string that looks like a number and represents an integer.</p>

<ul>

<li><p>Leading and trailing whitespace is ignored.</p>

</li>
<li><p>Leading and trailing zeros are ignored.</p>

</li>
<li><p>If the string has a &quot;0x&quot; prefix, it is interpreted as a hexadecimal number.</p>

</li>
<li><p>If the string has a &quot;0b&quot; prefix, it is interpreted as a binary number.</p>

</li>
<li><p>One underline is allowed between any two digits.</p>

</li>
<li><p>If the string can not be interpreted, NaN is returned.</p>

</li>
</ul>

<p>Octal numbers are typically prefixed by &quot;0&quot;, but since leading zeros are stripped, these methods can not automatically recognize octal numbers, so use the constructor from_oct() to interpret octal strings.</p>

<p>Some examples of valid string input</p>

<pre><code class="plaintext">Input string                Resulting value
123                         123
1.23e2                      123
12300e-2                    123
0xcafe                      51966
0b1101                      13
67_538_754                  67538754
-4_5_6.7_8_9e+0_1_0         -4567890000000</code></pre>

<p>Input given as scalar numbers might lose precision. Quote your input to ensure that no digits are lost:</p>

<pre><code>$x = Math::BigInt-&gt;new( 56789012345678901234 );   # bad
$x = Math::BigInt-&gt;new(&#39;56789012345678901234&#39;);   # good</code></pre>

<p>Currently, Math::BigInt-&gt;new() defaults to 0, while Math::BigInt-&gt;new(&#39;&#39;) results in &#39;NaN&#39;. This might change in the future, so use always the following explicit forms to get a zero or NaN:</p>

<pre><code>$zero = Math::BigInt-&gt;bzero();
$nan  = Math::BigInt-&gt;bnan();</code></pre>

<h2 id="Output"><a class="permalink" href="./Math::BigInt.html#Output">#</a>Output</h2>

<p>Output values are usually Math::BigInt objects.</p>

<p>Boolean operators <code>is_zero()</code>, <code>is_one()</code>, <code>is_inf()</code>, etc. return true or false.</p>

<p>Comparison operators <code>bcmp()</code> and <code>bacmp()</code>) return -1, 0, 1, or undef.</p>

<h1 id="METHODS"><a class="permalink" href="./Math::BigInt.html#METHODS">#</a>METHODS</h1>

<h2 id="Configuration-methods"><a class="permalink" href="./Math::BigInt.html#Configuration-methods">#</a><a id="Configuration"></a>Configuration methods</h2>

<p>Each of the methods below (except config(), accuracy() and precision()) accepts three additional parameters. These arguments <code>$A</code>, <code>$P</code> and <code>$R</code> are <code>accuracy</code>, <code>precision</code> and <code>round_mode</code>. Please see the section about <a href="./Math::BigInt.html#ACCURACY-and-PRECISION">&quot;ACCURACY and PRECISION&quot;</a> for more information.</p>

<p>Setting a class variable effects all object instance that are created afterwards.</p>

<dl>

<dt id="accuracy()"><a class="permalink" href="./Math::BigInt.html#accuracy()">#</a><a id="accuracy"></a>accuracy()</dt>
<dd>

<pre><code>Math::BigInt-&gt;accuracy(5);      # set class accuracy
$x-&gt;accuracy(5);                # set instance accuracy

$A = Math::BigInt-&gt;accuracy();  # get class accuracy
$A = $x-&gt;accuracy();            # get instance accuracy</code></pre>

<p>Set or get the accuracy, i.e., the number of significant digits. The accuracy must be an integer. If the accuracy is set to <code>undef</code>, no rounding is done.</p>

<p>Alternatively, one can round the results explicitly using one of <a href="./Math::BigInt.html#round%28%29">&quot;round()&quot;</a>, <a href="./Math::BigInt.html#bround%28%29">&quot;bround()&quot;</a> or <a href="./Math::BigInt.html#bfround%28%29">&quot;bfround()&quot;</a> or by passing the desired accuracy to the method as an additional parameter:</p>

<pre><code>my $x = Math::BigInt-&gt;new(30000);
my $y = Math::BigInt-&gt;new(7);
print scalar $x-&gt;copy()-&gt;bdiv($y, 2);               # prints 4300
print scalar $x-&gt;copy()-&gt;bdiv($y)-&gt;bround(2);       # prints 4300</code></pre>

<p>Please see the section about <a href="./Math::BigInt.html#ACCURACY-and-PRECISION">&quot;ACCURACY and PRECISION&quot;</a> for further details.</p>

<pre><code>$y = Math::BigInt-&gt;new(1234567);    # $y is not rounded
Math::BigInt-&gt;accuracy(4);          # set class accuracy to 4
$x = Math::BigInt-&gt;new(1234567);    # $x is rounded automatically
print &quot;$x $y&quot;;                      # prints &quot;1235000 1234567&quot;

print $x-&gt;accuracy();       # prints &quot;4&quot;
print $y-&gt;accuracy();       # also prints &quot;4&quot;, since
                            #   class accuracy is 4

Math::BigInt-&gt;accuracy(5);  # set class accuracy to 5
print $x-&gt;accuracy();       # prints &quot;4&quot;, since instance
                            #   accuracy is 4
print $y-&gt;accuracy();       # prints &quot;5&quot;, since no instance
                            #   accuracy, and class accuracy is 5</code></pre>

<p>Note: Each class has it&#39;s own globals separated from Math::BigInt, but it is possible to subclass Math::BigInt and make the globals of the subclass aliases to the ones from Math::BigInt.</p>

</dd>
<dt id="precision()"><a class="permalink" href="./Math::BigInt.html#precision()">#</a><a id="precision"></a>precision()</dt>
<dd>

<pre><code>Math::BigInt-&gt;precision(-2);     # set class precision
$x-&gt;precision(-2);               # set instance precision

$P = Math::BigInt-&gt;precision();  # get class precision
$P = $x-&gt;precision();            # get instance precision</code></pre>

<p>Set or get the precision, i.e., the place to round relative to the decimal point. The precision must be a integer. Setting the precision to $P means that each number is rounded up or down, depending on the rounding mode, to the nearest multiple of 10**$P. If the precision is set to <code>undef</code>, no rounding is done.</p>

<p>You might want to use <a href="./Math::BigInt.html#accuracy%28%29">&quot;accuracy()&quot;</a> instead. With <a href="./Math::BigInt.html#accuracy%28%29">&quot;accuracy()&quot;</a> you set the number of digits each result should have, with <a href="./Math::BigInt.html#precision%28%29">&quot;precision()&quot;</a> you set the place where to round.</p>

<p>Please see the section about <a href="./Math::BigInt.html#ACCURACY-and-PRECISION">&quot;ACCURACY and PRECISION&quot;</a> for further details.</p>

<pre><code>$y = Math::BigInt-&gt;new(1234567);    # $y is not rounded
Math::BigInt-&gt;precision(4);         # set class precision to 4
$x = Math::BigInt-&gt;new(1234567);    # $x is rounded automatically
print $x;                           # prints &quot;1230000&quot;</code></pre>

<p>Note: Each class has its own globals separated from Math::BigInt, but it is possible to subclass Math::BigInt and make the globals of the subclass aliases to the ones from Math::BigInt.</p>

</dd>
<dt id="div_scale()"><a class="permalink" href="./Math::BigInt.html#div_scale()">#</a><a id="div_scale"></a>div_scale()</dt>
<dd>

<p>Set/get the fallback accuracy. This is the accuracy used when neither accuracy nor precision is set explicitly. It is used when a computation might otherwise attempt to return an infinite number of digits.</p>

</dd>
<dt id="round_mode()"><a class="permalink" href="./Math::BigInt.html#round_mode()">#</a><a id="round_mode"></a>round_mode()</dt>
<dd>

<p>Set/get the rounding mode.</p>

</dd>
<dt id="upgrade()"><a class="permalink" href="./Math::BigInt.html#upgrade()">#</a><a id="upgrade"></a>upgrade()</dt>
<dd>

<p>Set/get the class for upgrading. When a computation might result in a non-integer, the operands are upgraded to this class. This is used for instance by <a href="bignum.html">bignum</a>. The default is <code>undef</code>, thus the following operation creates a Math::BigInt, not a Math::BigFloat:</p>

<pre><code>my $i = Math::BigInt-&gt;new(123);
my $f = Math::BigFloat-&gt;new(&#39;123.1&#39;);

print $i + $f, &quot;\n&quot;;                # prints 246</code></pre>

</dd>
<dt id="downgrade()"><a class="permalink" href="./Math::BigInt.html#downgrade()">#</a><a id="downgrade"></a>downgrade()</dt>
<dd>

<p>Set/get the class for downgrading. The default is <code>undef</code>. Downgrading is not done by Math::BigInt.</p>

</dd>
<dt id="modify()"><a class="permalink" href="./Math::BigInt.html#modify()">#</a><a id="modify"></a>modify()</dt>
<dd>

<pre><code>$x-&gt;modify(&#39;bpowd&#39;);</code></pre>

<p>This method returns 0 if the object can be modified with the given operation, or 1 if not.</p>

<p>This is used for instance by <a href="./Math::BigInt::Constant.html">Math::BigInt::Constant</a>.</p>

</dd>
<dt id="config()"><a class="permalink" href="./Math::BigInt.html#config()">#</a><a id="config"></a>config()</dt>
<dd>

<pre><code>Math::BigInt-&gt;config(&quot;trap_nan&quot; =&gt; 1);      # set
$accu = Math::BigInt-&gt;config(&quot;accuracy&quot;);   # get</code></pre>

<p>Set or get class variables. Read-only parameters are marked as RO. Read-write parameters are marked as RW. The following parameters are supported.</p>

<pre><code class="plaintext">Parameter       RO/RW   Description
                        Example
============================================================
lib             RO      Name of the math backend library
                        Math::BigInt::Calc
lib_version     RO      Version of the math backend library
                        0.30
class           RO      The class of config you just called
                        Math::BigRat
version         RO      version number of the class you used
                        0.10
upgrade         RW      To which class numbers are upgraded
                        undef
downgrade       RW      To which class numbers are downgraded
                        undef
precision       RW      Global precision
                        undef
accuracy        RW      Global accuracy
                        undef
round_mode      RW      Global round mode
                        even
div_scale       RW      Fallback accuracy for division etc.
                        40
trap_nan        RW      Trap NaNs
                        undef
trap_inf        RW      Trap +inf/-inf
                        undef</code></pre>

</dd>
</dl>

<h2 id="Constructor-methods"><a class="permalink" href="./Math::BigInt.html#Constructor-methods">#</a><a id="Constructor"></a>Constructor methods</h2>

<dl>

<dt id="new()"><a class="permalink" href="./Math::BigInt.html#new()">#</a><a id="new"></a>new()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;new($str,$A,$P,$R);</code></pre>

<p>Creates a new Math::BigInt object from a scalar or another Math::BigInt object. The input is accepted as decimal, hexadecimal (with leading &#39;0x&#39;) or binary (with leading &#39;0b&#39;).</p>

<p>See <a href="./Math::BigInt.html#Input">&quot;Input&quot;</a> for more info on accepted input formats.</p>

</dd>
<dt id="from_hex()"><a class="permalink" href="./Math::BigInt.html#from_hex()">#</a><a id="from_hex"></a>from_hex()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;from_hex(&quot;0xcafe&quot;);    # input is hexadecimal</code></pre>

<p>Interpret input as a hexadecimal string. A &quot;0x&quot; or &quot;x&quot; prefix is optional. A single underscore character may be placed right after the prefix, if present, or between any two digits. If the input is invalid, a NaN is returned.</p>

</dd>
<dt id="from_oct()"><a class="permalink" href="./Math::BigInt.html#from_oct()">#</a><a id="from_oct"></a>from_oct()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;from_oct(&quot;0775&quot;);      # input is octal</code></pre>

<p>Interpret the input as an octal string and return the corresponding value. A &quot;0&quot; (zero) prefix is optional. A single underscore character may be placed right after the prefix, if present, or between any two digits. If the input is invalid, a NaN is returned.</p>

</dd>
<dt id="from_bin()"><a class="permalink" href="./Math::BigInt.html#from_bin()">#</a><a id="from_bin"></a>from_bin()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;from_bin(&quot;0b10011&quot;);   # input is binary</code></pre>

<p>Interpret the input as a binary string. A &quot;0b&quot; or &quot;b&quot; prefix is optional. A single underscore character may be placed right after the prefix, if present, or between any two digits. If the input is invalid, a NaN is returned.</p>

</dd>
<dt id="from_bytes()"><a class="permalink" href="./Math::BigInt.html#from_bytes()">#</a><a id="from_bytes"></a>from_bytes()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;from_bytes(&quot;\xf3\x6b&quot;);  # $x = 62315</code></pre>

<p>Interpret the input as a byte string, assuming big endian byte order. The output is always a non-negative, finite integer.</p>

<p>In some special cases, from_bytes() matches the conversion done by unpack():</p>

<pre><code>$b = &quot;\x4e&quot;;                             # one char byte string
$x = Math::BigInt-&gt;from_bytes($b);       # = 78
$y = unpack &quot;C&quot;, $b;                     # ditto, but scalar

$b = &quot;\xf3\x6b&quot;;                         # two char byte string
$x = Math::BigInt-&gt;from_bytes($b);       # = 62315
$y = unpack &quot;S&gt;&quot;, $b;                    # ditto, but scalar

$b = &quot;\x2d\xe0\x49\xad&quot;;                 # four char byte string
$x = Math::BigInt-&gt;from_bytes($b);       # = 769673645
$y = unpack &quot;L&gt;&quot;, $b;                    # ditto, but scalar

$b = &quot;\x2d\xe0\x49\xad\x2d\xe0\x49\xad&quot;; # eight char byte string
$x = Math::BigInt-&gt;from_bytes($b);       # = 3305723134637787565
$y = unpack &quot;Q&gt;&quot;, $b;                    # ditto, but scalar</code></pre>

</dd>
<dt id="from_base()"><a class="permalink" href="./Math::BigInt.html#from_base()">#</a><a id="from_base"></a>from_base()</dt>
<dd>

<p>Given a string, a base, and an optional collation sequence, interpret the string as a number in the given base. The collation sequence describes the value of each character in the string.</p>

<p>If a collation sequence is not given, a default collation sequence is used. If the base is less than or equal to 36, the collation sequence is the string consisting of the 36 characters &quot;0&quot; to &quot;9&quot; and &quot;A&quot; to &quot;Z&quot;. In this case, the letter case in the input is ignored. If the base is greater than 36, and smaller than or equal to 62, the collation sequence is the string consisting of the 62 characters &quot;0&quot; to &quot;9&quot;, &quot;A&quot; to &quot;Z&quot;, and &quot;a&quot; to &quot;z&quot;. A base larger than 62 requires the collation sequence to be specified explicitly.</p>

<p>These examples show standard binary, octal, and hexadecimal conversion. All cases return 250.</p>

<pre><code>$x = Math::BigInt-&gt;from_base(&quot;11111010&quot;, 2);
$x = Math::BigInt-&gt;from_base(&quot;372&quot;, 8);
$x = Math::BigInt-&gt;from_base(&quot;fa&quot;, 16);</code></pre>

<p>When the base is less than or equal to 36, and no collation sequence is given, the letter case is ignored, so both of these also return 250:</p>

<pre><code>$x = Math::BigInt-&gt;from_base(&quot;6Y&quot;, 16);
$x = Math::BigInt-&gt;from_base(&quot;6y&quot;, 16);</code></pre>

<p>When the base greater than 36, and no collation sequence is given, the default collation sequence contains both uppercase and lowercase letters, so the letter case in the input is not ignored:</p>

<pre><code>$x = Math::BigInt-&gt;from_base(&quot;6S&quot;, 37);         # $x is 250
$x = Math::BigInt-&gt;from_base(&quot;6s&quot;, 37);         # $x is 276
$x = Math::BigInt-&gt;from_base(&quot;121&quot;, 3);         # $x is 16
$x = Math::BigInt-&gt;from_base(&quot;XYZ&quot;, 36);        # $x is 44027
$x = Math::BigInt-&gt;from_base(&quot;Why&quot;, 42);        # $x is 58314</code></pre>

<p>The collation sequence can be any set of unique characters. These two cases are equivalent</p>

<pre><code>$x = Math::BigInt-&gt;from_base(&quot;100&quot;, 2, &quot;01&quot;);   # $x is 4
$x = Math::BigInt-&gt;from_base(&quot;|--&quot;, 2, &quot;-|&quot;);   # $x is 4</code></pre>

</dd>
<dt id="bzero()"><a class="permalink" href="./Math::BigInt.html#bzero()">#</a><a id="bzero"></a>bzero()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;bzero();
$x-&gt;bzero();</code></pre>

<p>Returns a new Math::BigInt object representing zero. If used as an instance method, assigns the value to the invocand.</p>

</dd>
<dt id="bone()"><a class="permalink" href="./Math::BigInt.html#bone()">#</a><a id="bone"></a>bone()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;bone();          # +1
$x = Math::BigInt-&gt;bone(&quot;+&quot;);       # +1
$x = Math::BigInt-&gt;bone(&quot;-&quot;);       # -1
$x-&gt;bone();                         # +1
$x-&gt;bone(&quot;+&quot;);                      # +1
$x-&gt;bone(&#39;-&#39;);                      # -1</code></pre>

<p>Creates a new Math::BigInt object representing one. The optional argument is either &#39;-&#39; or &#39;+&#39;, indicating whether you want plus one or minus one. If used as an instance method, assigns the value to the invocand.</p>

</dd>
<dt id="binf()"><a class="permalink" href="./Math::BigInt.html#binf()">#</a><a id="binf"></a>binf()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;binf($sign);</code></pre>

<p>Creates a new Math::BigInt object representing infinity. The optional argument is either &#39;-&#39; or &#39;+&#39;, indicating whether you want infinity or minus infinity. If used as an instance method, assigns the value to the invocand.</p>

<pre><code>$x-&gt;binf();
$x-&gt;binf(&#39;-&#39;);</code></pre>

</dd>
<dt id="bnan()"><a class="permalink" href="./Math::BigInt.html#bnan()">#</a><a id="bnan"></a>bnan()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;bnan();</code></pre>

<p>Creates a new Math::BigInt object representing NaN (Not A Number). If used as an instance method, assigns the value to the invocand.</p>

<pre><code>$x-&gt;bnan();</code></pre>

</dd>
<dt id="bpi()"><a class="permalink" href="./Math::BigInt.html#bpi()">#</a><a id="bpi"></a>bpi()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;bpi(100);        # 3
$x-&gt;bpi(100);                       # 3</code></pre>

<p>Creates a new Math::BigInt object representing PI. If used as an instance method, assigns the value to the invocand. With Math::BigInt this always returns 3.</p>

<p>If upgrading is in effect, returns PI, rounded to N digits with the current rounding mode:</p>

<pre><code>use Math::BigFloat;
use Math::BigInt upgrade =&gt; &quot;Math::BigFloat&quot;;
print Math::BigInt-&gt;bpi(3), &quot;\n&quot;;           # 3.14
print Math::BigInt-&gt;bpi(100), &quot;\n&quot;;         # 3.1415....</code></pre>

</dd>
<dt id="copy()"><a class="permalink" href="./Math::BigInt.html#copy()">#</a><a id="copy"></a>copy()</dt>
<dd>

<pre><code>$x-&gt;copy();         # make a true copy of $x (unlike $y = $x)</code></pre>

</dd>
<dt id="as_int()"><a class="permalink" href="./Math::BigInt.html#as_int()">#</a><a id="as_int"></a>as_int()</dt>
<dd>

</dd>
<dt id="as_number()"><a class="permalink" href="./Math::BigInt.html#as_number()">#</a><a id="as_number"></a>as_number()</dt>
<dd>

<p>These methods are called when Math::BigInt encounters an object it doesn&#39;t know how to handle. For instance, assume $x is a Math::BigInt, or subclass thereof, and $y is defined, but not a Math::BigInt, or subclass thereof. If you do</p>

<pre><code>$x -&gt; badd($y);</code></pre>

<p>$y needs to be converted into an object that $x can deal with. This is done by first checking if $y is something that $x might be upgraded to. If that is the case, no further attempts are made. The next is to see if $y supports the method <code>as_int()</code>. If it does, <code>as_int()</code> is called, but if it doesn&#39;t, the next thing is to see if $y supports the method <code>as_number()</code>. If it does, <code>as_number()</code> is called. The method <code>as_int()</code> (and <code>as_number()</code>) is expected to return either an object that has the same class as $x, a subclass thereof, or a string that <code>ref($x)-&gt;new()</code> can parse to create an object.</p>

<p><code>as_number()</code> is an alias to <code>as_int()</code>. <code>as_number</code> was introduced in v1.22, while <code>as_int()</code> was introduced in v1.68.</p>

<p>In Math::BigInt, <code>as_int()</code> has the same effect as <code>copy()</code>.</p>

</dd>
</dl>

<h2 id="Boolean-methods"><a class="permalink" href="./Math::BigInt.html#Boolean-methods">#</a><a id="Boolean"></a>Boolean methods</h2>

<p>None of these methods modify the invocand object.</p>

<dl>

<dt id="is_zero()"><a class="permalink" href="./Math::BigInt.html#is_zero()">#</a><a id="is_zero"></a>is_zero()</dt>
<dd>

<pre><code>$x-&gt;is_zero();              # true if $x is 0</code></pre>

<p>Returns true if the invocand is zero and false otherwise.</p>

</dd>
<dt id="is_one(-[-SIGN-])"><a class="permalink" href="./Math::BigInt.html#is_one(-%5B-SIGN-%5D)">#</a><a id="is_one"></a><a id="is_one-SIGN"></a>is_one( [ SIGN ])</dt>
<dd>

<pre><code>$x-&gt;is_one();               # true if $x is +1
$x-&gt;is_one(&quot;+&quot;);            # ditto
$x-&gt;is_one(&quot;-&quot;);            # true if $x is -1</code></pre>

<p>Returns true if the invocand is one and false otherwise.</p>

</dd>
<dt id="is_finite()"><a class="permalink" href="./Math::BigInt.html#is_finite()">#</a><a id="is_finite"></a>is_finite()</dt>
<dd>

<pre><code>$x-&gt;is_finite();    # true if $x is not +inf, -inf or NaN</code></pre>

<p>Returns true if the invocand is a finite number, i.e., it is neither +inf, -inf, nor NaN.</p>

</dd>
<dt id="is_inf(-[-SIGN-]-)"><a class="permalink" href="./Math::BigInt.html#is_inf(-%5B-SIGN-%5D-)">#</a><a id="is_inf"></a><a id="is_inf-SIGN"></a>is_inf( [ SIGN ] )</dt>
<dd>

<pre><code>$x-&gt;is_inf();               # true if $x is +inf
$x-&gt;is_inf(&quot;+&quot;);            # ditto
$x-&gt;is_inf(&quot;-&quot;);            # true if $x is -inf</code></pre>

<p>Returns true if the invocand is infinite and false otherwise.</p>

</dd>
<dt id="is_nan()"><a class="permalink" href="./Math::BigInt.html#is_nan()">#</a><a id="is_nan"></a>is_nan()</dt>
<dd>

<pre><code>$x-&gt;is_nan();               # true if $x is NaN</code></pre>

</dd>
<dt id="is_positive()"><a class="permalink" href="./Math::BigInt.html#is_positive()">#</a><a id="is_positive"></a>is_positive()</dt>
<dd>

</dd>
<dt id="is_pos()"><a class="permalink" href="./Math::BigInt.html#is_pos()">#</a><a id="is_pos"></a>is_pos()</dt>
<dd>

<pre><code>$x-&gt;is_positive();          # true if &gt; 0
$x-&gt;is_pos();               # ditto</code></pre>

<p>Returns true if the invocand is positive and false otherwise. A <code>NaN</code> is neither positive nor negative.</p>

</dd>
<dt id="is_negative()"><a class="permalink" href="./Math::BigInt.html#is_negative()">#</a><a id="is_negative"></a>is_negative()</dt>
<dd>

</dd>
<dt id="is_neg()"><a class="permalink" href="./Math::BigInt.html#is_neg()">#</a><a id="is_neg"></a>is_neg()</dt>
<dd>

<pre><code>$x-&gt;is_negative();          # true if &lt; 0
$x-&gt;is_neg();               # ditto</code></pre>

<p>Returns true if the invocand is negative and false otherwise. A <code>NaN</code> is neither positive nor negative.</p>

</dd>
<dt id="is_non_positive()"><a class="permalink" href="./Math::BigInt.html#is_non_positive()">#</a><a id="is_non_positive"></a>is_non_positive()</dt>
<dd>

<pre><code>$x-&gt;is_non_positive();      # true if &lt;= 0</code></pre>

<p>Returns true if the invocand is negative or zero.</p>

</dd>
<dt id="is_non_negative()"><a class="permalink" href="./Math::BigInt.html#is_non_negative()">#</a><a id="is_non_negative"></a>is_non_negative()</dt>
<dd>

<pre><code>$x-&gt;is_non_negative();      # true if &gt;= 0</code></pre>

<p>Returns true if the invocand is positive or zero.</p>

</dd>
<dt id="is_odd()"><a class="permalink" href="./Math::BigInt.html#is_odd()">#</a><a id="is_odd"></a>is_odd()</dt>
<dd>

<pre><code>$x-&gt;is_odd();               # true if odd, false for even</code></pre>

<p>Returns true if the invocand is odd and false otherwise. <code>NaN</code>, <code>+inf</code>, and <code>-inf</code> are neither odd nor even.</p>

</dd>
<dt id="is_even()"><a class="permalink" href="./Math::BigInt.html#is_even()">#</a><a id="is_even"></a>is_even()</dt>
<dd>

<pre><code>$x-&gt;is_even();              # true if $x is even</code></pre>

<p>Returns true if the invocand is even and false otherwise. <code>NaN</code>, <code>+inf</code>, <code>-inf</code> are not integers and are neither odd nor even.</p>

</dd>
<dt id="is_int()"><a class="permalink" href="./Math::BigInt.html#is_int()">#</a><a id="is_int"></a>is_int()</dt>
<dd>

<pre><code>$x-&gt;is_int();               # true if $x is an integer</code></pre>

<p>Returns true if the invocand is an integer and false otherwise. <code>NaN</code>, <code>+inf</code>, <code>-inf</code> are not integers.</p>

</dd>
</dl>

<h2 id="Comparison-methods"><a class="permalink" href="./Math::BigInt.html#Comparison-methods">#</a><a id="Comparison"></a>Comparison methods</h2>

<p>None of these methods modify the invocand object. Note that a <code>NaN</code> is neither less than, greater than, or equal to anything else, even a <code>NaN</code>.</p>

<dl>

<dt id="bcmp()"><a class="permalink" href="./Math::BigInt.html#bcmp()">#</a><a id="bcmp"></a>bcmp()</dt>
<dd>

<pre><code>$x-&gt;bcmp($y);</code></pre>

<p>Returns -1, 0, 1 depending on whether $x is less than, equal to, or grater than $y. Returns undef if any operand is a NaN.</p>

</dd>
<dt id="bacmp()"><a class="permalink" href="./Math::BigInt.html#bacmp()">#</a><a id="bacmp"></a>bacmp()</dt>
<dd>

<pre><code>$x-&gt;bacmp($y);</code></pre>

<p>Returns -1, 0, 1 depending on whether the absolute value of $x is less than, equal to, or grater than the absolute value of $y. Returns undef if any operand is a NaN.</p>

</dd>
<dt id="beq()"><a class="permalink" href="./Math::BigInt.html#beq()">#</a><a id="beq"></a>beq()</dt>
<dd>

<pre><code>$x -&gt; beq($y);</code></pre>

<p>Returns true if and only if $x is equal to $y, and false otherwise.</p>

</dd>
<dt id="bne()"><a class="permalink" href="./Math::BigInt.html#bne()">#</a><a id="bne"></a>bne()</dt>
<dd>

<pre><code>$x -&gt; bne($y);</code></pre>

<p>Returns true if and only if $x is not equal to $y, and false otherwise.</p>

</dd>
<dt id="blt()"><a class="permalink" href="./Math::BigInt.html#blt()">#</a><a id="blt"></a>blt()</dt>
<dd>

<pre><code>$x -&gt; blt($y);</code></pre>

<p>Returns true if and only if $x is equal to $y, and false otherwise.</p>

</dd>
<dt id="ble()"><a class="permalink" href="./Math::BigInt.html#ble()">#</a><a id="ble"></a>ble()</dt>
<dd>

<pre><code>$x -&gt; ble($y);</code></pre>

<p>Returns true if and only if $x is less than or equal to $y, and false otherwise.</p>

</dd>
<dt id="bgt()"><a class="permalink" href="./Math::BigInt.html#bgt()">#</a><a id="bgt"></a>bgt()</dt>
<dd>

<pre><code>$x -&gt; bgt($y);</code></pre>

<p>Returns true if and only if $x is greater than $y, and false otherwise.</p>

</dd>
<dt id="bge()"><a class="permalink" href="./Math::BigInt.html#bge()">#</a><a id="bge"></a>bge()</dt>
<dd>

<pre><code>$x -&gt; bge($y);</code></pre>

<p>Returns true if and only if $x is greater than or equal to $y, and false otherwise.</p>

</dd>
</dl>

<h2 id="Arithmetic-methods"><a class="permalink" href="./Math::BigInt.html#Arithmetic-methods">#</a><a id="Arithmetic"></a>Arithmetic methods</h2>

<p>These methods modify the invocand object and returns it.</p>

<dl>

<dt id="bneg()"><a class="permalink" href="./Math::BigInt.html#bneg()">#</a><a id="bneg"></a>bneg()</dt>
<dd>

<pre><code>$x-&gt;bneg();</code></pre>

<p>Negate the number, e.g. change the sign between &#39;+&#39; and &#39;-&#39;, or between &#39;+inf&#39; and &#39;-inf&#39;, respectively. Does nothing for NaN or zero.</p>

</dd>
<dt id="babs()"><a class="permalink" href="./Math::BigInt.html#babs()">#</a><a id="babs"></a>babs()</dt>
<dd>

<pre><code>$x-&gt;babs();</code></pre>

<p>Set the number to its absolute value, e.g. change the sign from &#39;-&#39; to &#39;+&#39; and from &#39;-inf&#39; to &#39;+inf&#39;, respectively. Does nothing for NaN or positive numbers.</p>

</dd>
<dt id="bsgn()"><a class="permalink" href="./Math::BigInt.html#bsgn()">#</a><a id="bsgn"></a>bsgn()</dt>
<dd>

<pre><code>$x-&gt;bsgn();</code></pre>

<p>Signum function. Set the number to -1, 0, or 1, depending on whether the number is negative, zero, or positive, respectively. Does not modify NaNs.</p>

</dd>
<dt id="bnorm()"><a class="permalink" href="./Math::BigInt.html#bnorm()">#</a><a id="bnorm"></a>bnorm()</dt>
<dd>

<pre><code>$x-&gt;bnorm();                        # normalize (no-op)</code></pre>

<p>Normalize the number. This is a no-op and is provided only for backwards compatibility.</p>

</dd>
<dt id="binc()"><a class="permalink" href="./Math::BigInt.html#binc()">#</a><a id="binc"></a>binc()</dt>
<dd>

<pre><code>$x-&gt;binc();                 # increment x by 1</code></pre>

</dd>
<dt id="bdec()"><a class="permalink" href="./Math::BigInt.html#bdec()">#</a><a id="bdec"></a>bdec()</dt>
<dd>

<pre><code>$x-&gt;bdec();                 # decrement x by 1</code></pre>

</dd>
<dt id="badd()"><a class="permalink" href="./Math::BigInt.html#badd()">#</a><a id="badd"></a>badd()</dt>
<dd>

<pre><code>$x-&gt;badd($y);               # addition (add $y to $x)</code></pre>

</dd>
<dt id="bsub()"><a class="permalink" href="./Math::BigInt.html#bsub()">#</a><a id="bsub"></a>bsub()</dt>
<dd>

<pre><code>$x-&gt;bsub($y);               # subtraction (subtract $y from $x)</code></pre>

</dd>
<dt id="bmul()"><a class="permalink" href="./Math::BigInt.html#bmul()">#</a><a id="bmul"></a>bmul()</dt>
<dd>

<pre><code>$x-&gt;bmul($y);               # multiplication (multiply $x by $y)</code></pre>

</dd>
<dt id="bmuladd()"><a class="permalink" href="./Math::BigInt.html#bmuladd()">#</a><a id="bmuladd"></a>bmuladd()</dt>
<dd>

<pre><code>$x-&gt;bmuladd($y,$z);</code></pre>

<p>Multiply $x by $y, and then add $z to the result,</p>

<p>This method was added in v1.87 of Math::BigInt (June 2007).</p>

</dd>
<dt id="bdiv()"><a class="permalink" href="./Math::BigInt.html#bdiv()">#</a><a id="bdiv"></a>bdiv()</dt>
<dd>

<pre><code>$x-&gt;bdiv($y);               # divide, set $x to quotient</code></pre>

<p>Divides $x by $y by doing floored division (F-division), where the quotient is the floored (rounded towards negative infinity) quotient of the two operands. In list context, returns the quotient and the remainder. The remainder is either zero or has the same sign as the second operand. In scalar context, only the quotient is returned.</p>

<p>The quotient is always the greatest integer less than or equal to the real-valued quotient of the two operands, and the remainder (when it is non-zero) always has the same sign as the second operand; so, for example,</p>

<pre><code class="plaintext">  1 /  4  =&gt; ( 0,  1)
  1 / -4  =&gt; (-1, -3)
 -3 /  4  =&gt; (-1,  1)
 -3 / -4  =&gt; ( 0, -3)
-11 /  2  =&gt; (-5,  1)
 11 / -2  =&gt; (-5, -1)</code></pre>

<p>The behavior of the overloaded operator % agrees with the behavior of Perl&#39;s built-in % operator (as documented in the perlop manpage), and the equation</p>

<pre><code>$x == ($x / $y) * $y + ($x % $y)</code></pre>

<p>holds true for any finite $x and finite, non-zero $y.</p>

<p>Perl&#39;s &quot;use integer&quot; might change the behaviour of % and / for scalars. This is because under &#39;use integer&#39; Perl does what the underlying C library thinks is right, and this varies. However, &quot;use integer&quot; does not change the way things are done with Math::BigInt objects.</p>

</dd>
<dt id="btdiv()"><a class="permalink" href="./Math::BigInt.html#btdiv()">#</a><a id="btdiv"></a>btdiv()</dt>
<dd>

<pre><code>$x-&gt;btdiv($y);              # divide, set $x to quotient</code></pre>

<p>Divides $x by $y by doing truncated division (T-division), where quotient is the truncated (rouneded towards zero) quotient of the two operands. In list context, returns the quotient and the remainder. The remainder is either zero or has the same sign as the first operand. In scalar context, only the quotient is returned.</p>

</dd>
<dt id="bmod()"><a class="permalink" href="./Math::BigInt.html#bmod()">#</a><a id="bmod"></a>bmod()</dt>
<dd>

<pre><code>$x-&gt;bmod($y);               # modulus (x % y)</code></pre>

<p>Returns $x modulo $y, i.e., the remainder after floored division (F-division). This method is like Perl&#39;s % operator. See <a href="./Math::BigInt.html#bdiv%28%29">&quot;bdiv()&quot;</a>.</p>

</dd>
<dt id="btmod()"><a class="permalink" href="./Math::BigInt.html#btmod()">#</a><a id="btmod"></a>btmod()</dt>
<dd>

<pre><code>$x-&gt;btmod($y);              # modulus</code></pre>

<p>Returns the remainer after truncated division (T-division). See <a href="./Math::BigInt.html#btdiv%28%29">&quot;btdiv()&quot;</a>.</p>

</dd>
<dt id="bmodinv()"><a class="permalink" href="./Math::BigInt.html#bmodinv()">#</a><a id="bmodinv"></a>bmodinv()</dt>
<dd>

<pre><code>$x-&gt;bmodinv($mod);          # modular multiplicative inverse</code></pre>

<p>Returns the multiplicative inverse of <code>$x</code> modulo <code>$mod</code>. If</p>

<pre><code>$y = $x -&gt; copy() -&gt; bmodinv($mod)</code></pre>

<p>then <code>$y</code> is the number closest to zero, and with the same sign as <code>$mod</code>, satisfying</p>

<pre><code>($x * $y) % $mod = 1 % $mod</code></pre>

<p>If <code>$x</code> and <code>$y</code> are non-zero, they must be relative primes, i.e., <code>bgcd($y, $mod)==1</code>. &#39;<code>NaN</code>&#39; is returned when no modular multiplicative inverse exists.</p>

</dd>
<dt id="bmodpow()"><a class="permalink" href="./Math::BigInt.html#bmodpow()">#</a><a id="bmodpow"></a>bmodpow()</dt>
<dd>

<pre><code>$num-&gt;bmodpow($exp,$mod);           # modular exponentiation
                                    # ($num**$exp % $mod)</code></pre>

<p>Returns the value of <code>$num</code> taken to the power <code>$exp</code> in the modulus <code>$mod</code> using binary exponentiation. <code>bmodpow</code> is far superior to writing</p>

<pre><code>$num ** $exp % $mod</code></pre>

<p>because it is much faster - it reduces internal variables into the modulus whenever possible, so it operates on smaller numbers.</p>

<p><code>bmodpow</code> also supports negative exponents.</p>

<pre><code>bmodpow($num, -1, $mod)</code></pre>

<p>is exactly equivalent to</p>

<pre><code>bmodinv($num, $mod)</code></pre>

</dd>
<dt id="bpow()"><a class="permalink" href="./Math::BigInt.html#bpow()">#</a><a id="bpow"></a>bpow()</dt>
<dd>

<pre><code>$x-&gt;bpow($y);               # power of arguments (x ** y)</code></pre>

<p><code>bpow()</code> (and the rounding functions) now modifies the first argument and returns it, unlike the old code which left it alone and only returned the result. This is to be consistent with <code>badd()</code> etc. The first three modifies $x, the last one won&#39;t:</p>

<pre><code>print bpow($x,$i),&quot;\n&quot;;         # modify $x
print $x-&gt;bpow($i),&quot;\n&quot;;        # ditto
print $x **= $i,&quot;\n&quot;;           # the same
print $x ** $i,&quot;\n&quot;;            # leave $x alone</code></pre>

<p>The form <code>$x **= $y</code> is faster than <code>$x = $x ** $y;</code>, though.</p>

</dd>
<dt id="blog()"><a class="permalink" href="./Math::BigInt.html#blog()">#</a><a id="blog"></a>blog()</dt>
<dd>

<pre><code>$x-&gt;blog($base, $accuracy);         # logarithm of x to the base $base</code></pre>

<p>If <code>$base</code> is not defined, Euler&#39;s number (e) is used:</p>

<pre><code>print $x-&gt;blog(undef, 100);         # log(x) to 100 digits</code></pre>

</dd>
<dt id="bexp()"><a class="permalink" href="./Math::BigInt.html#bexp()">#</a><a id="bexp"></a>bexp()</dt>
<dd>

<pre><code>$x-&gt;bexp($accuracy);                # calculate e ** X</code></pre>

<p>Calculates the expression <code>e ** $x</code> where <code>e</code> is Euler&#39;s number.</p>

<p>This method was added in v1.82 of Math::BigInt (April 2007).</p>

<p>See also <a href="./Math::BigInt.html#blog%28%29">&quot;blog()&quot;</a>.</p>

</dd>
<dt id="bnok()"><a class="permalink" href="./Math::BigInt.html#bnok()">#</a><a id="bnok"></a>bnok()</dt>
<dd>

<pre><code>$x-&gt;bnok($y);               # x over y (binomial coefficient n over k)</code></pre>

<p>Calculates the binomial coefficient n over k, also called the &quot;choose&quot; function, which is</p>

<pre><code class="plaintext">( n )       n!
|   |  = --------
( k )    k!(n-k)!</code></pre>

<p>when n and k are non-negative. This method implements the full Kronenburg extension (Kronenburg, M.J. &quot;The Binomial Coefficient for Negative Arguments.&quot; 18 May 2011. http://arxiv.org/abs/1105.3689/) illustrated by the following pseudo-code:</p>

<pre><code class="plaintext">if n &gt;= 0 and k &gt;= 0:
    return binomial(n, k)
if k &gt;= 0:
    return (-1)^k*binomial(-n+k-1, k)
if k &lt;= n:
    return (-1)^(n-k)*binomial(-k-1, n-k)
else
    return 0</code></pre>

<p>The behaviour is identical to the behaviour of the Maple and Mathematica function for negative integers n, k.</p>

</dd>
<dt id="buparrow()"><a class="permalink" href="./Math::BigInt.html#buparrow()">#</a><a id="buparrow"></a>buparrow()</dt>
<dd>

</dd>
<dt id="uparrow()"><a class="permalink" href="./Math::BigInt.html#uparrow()">#</a><a id="uparrow"></a>uparrow()</dt>
<dd>

<pre><code>$a -&gt; buparrow($n, $b);         # modifies $a
$x = $a -&gt; uparrow($n, $b);     # does not modify $a</code></pre>

<p>This method implements Knuth&#39;s up-arrow notation, where $n is a non-negative integer representing the number of up-arrows. $n = 0 gives multiplication, $n = 1 gives exponentiation, $n = 2 gives tetration, $n = 3 gives hexation etc. The following illustrates the relation between the first values of $n.</p>

<p>See <a href="https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation">https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation</a>.</p>

</dd>
<dt id="backermann()"><a class="permalink" href="./Math::BigInt.html#backermann()">#</a><a id="backermann"></a>backermann()</dt>
<dd>

</dd>
<dt id="ackermann()"><a class="permalink" href="./Math::BigInt.html#ackermann()">#</a><a id="ackermann"></a>ackermann()</dt>
<dd>

<pre><code>$m -&gt; backermann($n);           # modifies $a
$x = $m -&gt; ackermann($n);       # does not modify $a</code></pre>

<p>This method implements the Ackermann function:</p>

<pre><code class="plaintext">          / n + 1              if m = 0
A(m, n) = | A(m-1, 1)          if m &gt; 0 and n = 0
          \ A(m-1, A(m, n-1))  if m &gt; 0 and n &gt; 0</code></pre>

<p>Its value grows rapidly, even for small inputs. For example, A(4, 2) is an integer of 19729 decimal digits.</p>

<p>See https://en.wikipedia.org/wiki/Ackermann_function</p>

</dd>
<dt id="bsin()"><a class="permalink" href="./Math::BigInt.html#bsin()">#</a><a id="bsin"></a>bsin()</dt>
<dd>

<pre><code>my $x = Math::BigInt-&gt;new(1);
print $x-&gt;bsin(100), &quot;\n&quot;;</code></pre>

<p>Calculate the sine of $x, modifying $x in place.</p>

<p>In Math::BigInt, unless upgrading is in effect, the result is truncated to an integer.</p>

<p>This method was added in v1.87 of Math::BigInt (June 2007).</p>

</dd>
<dt id="bcos()"><a class="permalink" href="./Math::BigInt.html#bcos()">#</a><a id="bcos"></a>bcos()</dt>
<dd>

<pre><code>my $x = Math::BigInt-&gt;new(1);
print $x-&gt;bcos(100), &quot;\n&quot;;</code></pre>

<p>Calculate the cosine of $x, modifying $x in place.</p>

<p>In Math::BigInt, unless upgrading is in effect, the result is truncated to an integer.</p>

<p>This method was added in v1.87 of Math::BigInt (June 2007).</p>

</dd>
<dt id="batan()"><a class="permalink" href="./Math::BigInt.html#batan()">#</a><a id="batan"></a>batan()</dt>
<dd>

<pre><code>my $x = Math::BigFloat-&gt;new(0.5);
print $x-&gt;batan(100), &quot;\n&quot;;</code></pre>

<p>Calculate the arcus tangens of $x, modifying $x in place.</p>

<p>In Math::BigInt, unless upgrading is in effect, the result is truncated to an integer.</p>

<p>This method was added in v1.87 of Math::BigInt (June 2007).</p>

</dd>
<dt id="batan2()"><a class="permalink" href="./Math::BigInt.html#batan2()">#</a><a id="batan2"></a>batan2()</dt>
<dd>

<pre><code>my $x = Math::BigInt-&gt;new(1);
my $y = Math::BigInt-&gt;new(1);
print $y-&gt;batan2($x), &quot;\n&quot;;</code></pre>

<p>Calculate the arcus tangens of <code>$y</code> divided by <code>$x</code>, modifying $y in place.</p>

<p>In Math::BigInt, unless upgrading is in effect, the result is truncated to an integer.</p>

<p>This method was added in v1.87 of Math::BigInt (June 2007).</p>

</dd>
<dt id="bsqrt()"><a class="permalink" href="./Math::BigInt.html#bsqrt()">#</a><a id="bsqrt"></a>bsqrt()</dt>
<dd>

<pre><code>$x-&gt;bsqrt();                # calculate square root</code></pre>

<p><code>bsqrt()</code> returns the square root truncated to an integer.</p>

<p>If you want a better approximation of the square root, then use:</p>

<pre><code>$x = Math::BigFloat-&gt;new(12);
Math::BigFloat-&gt;precision(0);
Math::BigFloat-&gt;round_mode(&#39;even&#39;);
print $x-&gt;copy-&gt;bsqrt(),&quot;\n&quot;;           # 4

Math::BigFloat-&gt;precision(2);
print $x-&gt;bsqrt(),&quot;\n&quot;;                 # 3.46
print $x-&gt;bsqrt(3),&quot;\n&quot;;                # 3.464</code></pre>

</dd>
<dt id="broot()"><a class="permalink" href="./Math::BigInt.html#broot()">#</a><a id="broot"></a>broot()</dt>
<dd>

<pre><code>$x-&gt;broot($N);</code></pre>

<p>Calculates the N&#39;th root of <code>$x</code>.</p>

</dd>
<dt id="bfac()"><a class="permalink" href="./Math::BigInt.html#bfac()">#</a><a id="bfac"></a>bfac()</dt>
<dd>

<pre><code>$x-&gt;bfac();                 # factorial of $x (1*2*3*4*..*$x)</code></pre>

<p>Returns the factorial of <code>$x</code>, i.e., the product of all positive integers up to and including <code>$x</code>.</p>

</dd>
<dt id="bdfac()"><a class="permalink" href="./Math::BigInt.html#bdfac()">#</a><a id="bdfac"></a>bdfac()</dt>
<dd>

<pre><code>$x-&gt;bdfac();                # double factorial of $x (1*2*3*4*..*$x)</code></pre>

<p>Returns the double factorial of <code>$x</code>. If <code>$x</code> is an even integer, returns the product of all positive, even integers up to and including <code>$x</code>, i.e., 2*4*6*...*$x. If <code>$x</code> is an odd integer, returns the product of all positive, odd integers, i.e., 1*3*5*...*$x.</p>

</dd>
<dt id="bfib()"><a class="permalink" href="./Math::BigInt.html#bfib()">#</a><a id="bfib"></a>bfib()</dt>
<dd>

<pre><code>$F = $n-&gt;bfib();            # a single Fibonacci number
@F = $n-&gt;bfib();            # a list of Fibonacci numbers</code></pre>

<p>In scalar context, returns a single Fibonacci number. In list context, returns a list of Fibonacci numbers. The invocand is the last element in the output.</p>

<p>The Fibonacci sequence is defined by</p>

<pre><code class="plaintext">F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2)</code></pre>

<p>In list context, F(0) and F(n) is the first and last number in the output, respectively. For example, if $n is 12, then <code>@F = $n-&gt;bfib()</code> returns the following values, F(0) to F(12):</p>

<pre><code class="plaintext">0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144</code></pre>

<p>The sequence can also be extended to negative index n using the re-arranged recurrence relation</p>

<pre><code class="plaintext">F(n-2) = F(n) - F(n-1)</code></pre>

<p>giving the bidirectional sequence</p>

<pre><code class="plaintext">   n  -7  -6  -5  -4  -3  -2  -1   0   1   2   3   4   5   6   7
F(n)  13  -8   5  -3   2  -1   1   0   1   1   2   3   5   8  13</code></pre>

<p>If $n is -12, the following values, F(0) to F(12), are returned:</p>

<pre><code class="plaintext">0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144</code></pre>

</dd>
<dt id="blucas()"><a class="permalink" href="./Math::BigInt.html#blucas()">#</a><a id="blucas"></a>blucas()</dt>
<dd>

<pre><code>$F = $n-&gt;blucas();          # a single Lucas number
@F = $n-&gt;blucas();          # a list of Lucas numbers</code></pre>

<p>In scalar context, returns a single Lucas number. In list context, returns a list of Lucas numbers. The invocand is the last element in the output.</p>

<p>The Lucas sequence is defined by</p>

<pre><code class="plaintext">L(0) = 2
L(1) = 1
L(n) = L(n-1) + L(n-2)</code></pre>

<p>In list context, L(0) and L(n) is the first and last number in the output, respectively. For example, if $n is 12, then <code>@L = $n-&gt;blucas()</code> returns the following values, L(0) to L(12):</p>

<pre><code class="plaintext">2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322</code></pre>

<p>The sequence can also be extended to negative index n using the re-arranged recurrence relation</p>

<pre><code class="plaintext">L(n-2) = L(n) - L(n-1)</code></pre>

<p>giving the bidirectional sequence</p>

<pre><code class="plaintext">   n  -7  -6  -5  -4  -3  -2  -1   0   1   2   3   4   5   6   7
L(n)  29 -18  11  -7   4  -3   1   2   1   3   4   7  11  18  29</code></pre>

<p>If $n is -12, the following values, L(0) to L(-12), are returned:</p>

<pre><code class="plaintext">2, 1, -3, 4, -7, 11, -18, 29, -47, 76, -123, 199, -322</code></pre>

</dd>
<dt id="brsft()"><a class="permalink" href="./Math::BigInt.html#brsft()">#</a><a id="brsft"></a>brsft()</dt>
<dd>

<pre><code>$x-&gt;brsft($n);              # right shift $n places in base 2
$x-&gt;brsft($n, $b);          # right shift $n places in base $b</code></pre>

<p>The latter is equivalent to</p>

<pre><code>$x -&gt; bdiv($b -&gt; copy() -&gt; bpow($n))</code></pre>

</dd>
<dt id="blsft()"><a class="permalink" href="./Math::BigInt.html#blsft()">#</a><a id="blsft"></a>blsft()</dt>
<dd>

<pre><code>$x-&gt;blsft($n);              # left shift $n places in base 2
$x-&gt;blsft($n, $b);          # left shift $n places in base $b</code></pre>

<p>The latter is equivalent to</p>

<pre><code>$x -&gt; bmul($b -&gt; copy() -&gt; bpow($n))</code></pre>

</dd>
</dl>

<h2 id="Bitwise-methods"><a class="permalink" href="./Math::BigInt.html#Bitwise-methods">#</a><a id="Bitwise"></a>Bitwise methods</h2>

<dl>

<dt id="band()"><a class="permalink" href="./Math::BigInt.html#band()">#</a><a id="band"></a>band()</dt>
<dd>

<pre><code>$x-&gt;band($y);               # bitwise and</code></pre>

</dd>
<dt id="bior()"><a class="permalink" href="./Math::BigInt.html#bior()">#</a><a id="bior"></a>bior()</dt>
<dd>

<pre><code>$x-&gt;bior($y);               # bitwise inclusive or</code></pre>

</dd>
<dt id="bxor()"><a class="permalink" href="./Math::BigInt.html#bxor()">#</a><a id="bxor"></a>bxor()</dt>
<dd>

<pre><code>$x-&gt;bxor($y);               # bitwise exclusive or</code></pre>

</dd>
<dt id="bnot()"><a class="permalink" href="./Math::BigInt.html#bnot()">#</a><a id="bnot"></a>bnot()</dt>
<dd>

<pre><code>$x-&gt;bnot();                 # bitwise not (two&#39;s complement)</code></pre>

<p>Two&#39;s complement (bitwise not). This is equivalent to, but faster than,</p>

<pre><code>$x-&gt;binc()-&gt;bneg();</code></pre>

</dd>
</dl>

<h2 id="Rounding-methods"><a class="permalink" href="./Math::BigInt.html#Rounding-methods">#</a><a id="Rounding1"></a>Rounding methods</h2>

<dl>

<dt id="round()"><a class="permalink" href="./Math::BigInt.html#round()">#</a><a id="round"></a>round()</dt>
<dd>

<pre><code>$x-&gt;round($A,$P,$round_mode);</code></pre>

<p>Round $x to accuracy <code>$A</code> or precision <code>$P</code> using the round mode <code>$round_mode</code>.</p>

</dd>
<dt id="bround()"><a class="permalink" href="./Math::BigInt.html#bround()">#</a><a id="bround"></a>bround()</dt>
<dd>

<pre><code>$x-&gt;bround($N);               # accuracy: preserve $N digits</code></pre>

<p>Rounds $x to an accuracy of $N digits.</p>

</dd>
<dt id="bfround()"><a class="permalink" href="./Math::BigInt.html#bfround()">#</a><a id="bfround"></a>bfround()</dt>
<dd>

<pre><code>$x-&gt;bfround($N);</code></pre>

<p>Rounds to a multiple of 10**$N. Examples:</p>

<pre><code class="plaintext">Input            N          Result

123456.123456    3          123500
123456.123456    2          123450
123456.123456   -2          123456.12
123456.123456   -3          123456.123</code></pre>

</dd>
<dt id="bfloor()"><a class="permalink" href="./Math::BigInt.html#bfloor()">#</a><a id="bfloor"></a>bfloor()</dt>
<dd>

<pre><code>$x-&gt;bfloor();</code></pre>

<p>Round $x towards minus infinity, i.e., set $x to the largest integer less than or equal to $x.</p>

</dd>
<dt id="bceil()"><a class="permalink" href="./Math::BigInt.html#bceil()">#</a><a id="bceil"></a>bceil()</dt>
<dd>

<pre><code>$x-&gt;bceil();</code></pre>

<p>Round $x towards plus infinity, i.e., set $x to the smallest integer greater than or equal to $x).</p>

</dd>
<dt id="bint()"><a class="permalink" href="./Math::BigInt.html#bint()">#</a><a id="bint"></a>bint()</dt>
<dd>

<pre><code>$x-&gt;bint();</code></pre>

<p>Round $x towards zero.</p>

</dd>
</dl>

<h2 id="Other-mathematical-methods"><a class="permalink" href="./Math::BigInt.html#Other-mathematical-methods">#</a><a id="Other"></a>Other mathematical methods</h2>

<dl>

<dt id="bgcd()"><a class="permalink" href="./Math::BigInt.html#bgcd()">#</a><a id="bgcd"></a>bgcd()</dt>
<dd>

<pre><code>$x -&gt; bgcd($y);             # GCD of $x and $y
$x -&gt; bgcd($y, $z, ...);    # GCD of $x, $y, $z, ...</code></pre>

<p>Returns the greatest common divisor (GCD).</p>

</dd>
<dt id="blcm()"><a class="permalink" href="./Math::BigInt.html#blcm()">#</a><a id="blcm"></a>blcm()</dt>
<dd>

<pre><code>$x -&gt; blcm($y);             # LCM of $x and $y
$x -&gt; blcm($y, $z, ...);    # LCM of $x, $y, $z, ...</code></pre>

<p>Returns the least common multiple (LCM).</p>

</dd>
</dl>

<h2 id="Object-property-methods"><a class="permalink" href="./Math::BigInt.html#Object-property-methods">#</a><a id="Object"></a>Object property methods</h2>

<dl>

<dt id="sign()"><a class="permalink" href="./Math::BigInt.html#sign()">#</a><a id="sign"></a>sign()</dt>
<dd>

<pre><code>$x-&gt;sign();</code></pre>

<p>Return the sign, of $x, meaning either <code>+</code>, <code>-</code>, <code>-inf</code>, <code>+inf</code> or NaN.</p>

<p>If you want $x to have a certain sign, use one of the following methods:</p>

<pre><code>$x-&gt;babs();                 # &#39;+&#39;
$x-&gt;babs()-&gt;bneg();         # &#39;-&#39;
$x-&gt;bnan();                 # &#39;NaN&#39;
$x-&gt;binf();                 # &#39;+inf&#39;
$x-&gt;binf(&#39;-&#39;);              # &#39;-inf&#39;</code></pre>

</dd>
<dt id="digit()"><a class="permalink" href="./Math::BigInt.html#digit()">#</a><a id="digit"></a>digit()</dt>
<dd>

<pre><code>$x-&gt;digit($n);       # return the nth digit, counting from right</code></pre>

<p>If <code>$n</code> is negative, returns the digit counting from left.</p>

</dd>
<dt id="digitsum()"><a class="permalink" href="./Math::BigInt.html#digitsum()">#</a><a id="digitsum"></a>digitsum()</dt>
<dd>

<pre><code>$x-&gt;digitsum();</code></pre>

<p>Computes the sum of the base 10 digits and returns it.</p>

</dd>
<dt id="bdigitsum()"><a class="permalink" href="./Math::BigInt.html#bdigitsum()">#</a><a id="bdigitsum"></a>bdigitsum()</dt>
<dd>

<pre><code>$x-&gt;bdigitsum();</code></pre>

<p>Computes the sum of the base 10 digits and assigns the result to the invocand.</p>

</dd>
<dt id="length()"><a class="permalink" href="./Math::BigInt.html#length()">#</a><a id="length"></a>length()</dt>
<dd>

<pre><code>$x-&gt;length();
($xl, $fl) = $x-&gt;length();</code></pre>

<p>Returns the number of digits in the decimal representation of the number. In list context, returns the length of the integer and fraction part. For Math::BigInt objects, the length of the fraction part is always 0.</p>

<p>The following probably doesn&#39;t do what you expect:</p>

<pre><code>$c = Math::BigInt-&gt;new(123);
print $c-&gt;length(),&quot;\n&quot;;                # prints 30</code></pre>

<p>It prints both the number of digits in the number and in the fraction part since print calls <code>length()</code> in list context. Use something like:</p>

<pre><code>print scalar $c-&gt;length(),&quot;\n&quot;;         # prints 3</code></pre>

</dd>
<dt id="mantissa()"><a class="permalink" href="./Math::BigInt.html#mantissa()">#</a><a id="mantissa"></a>mantissa()</dt>
<dd>

<pre><code>$x-&gt;mantissa();</code></pre>

<p>Return the signed mantissa of $x as a Math::BigInt.</p>

</dd>
<dt id="exponent()"><a class="permalink" href="./Math::BigInt.html#exponent()">#</a><a id="exponent"></a>exponent()</dt>
<dd>

<pre><code>$x-&gt;exponent();</code></pre>

<p>Return the exponent of $x as a Math::BigInt.</p>

</dd>
<dt id="parts()"><a class="permalink" href="./Math::BigInt.html#parts()">#</a><a id="parts"></a>parts()</dt>
<dd>

<pre><code>$x-&gt;parts();</code></pre>

<p>Returns the significand (mantissa) and the exponent as integers. In Math::BigFloat, both are returned as Math::BigInt objects.</p>

</dd>
<dt id="sparts()"><a class="permalink" href="./Math::BigInt.html#sparts()">#</a><a id="sparts"></a>sparts()</dt>
<dd>

<p>Returns the significand (mantissa) and the exponent as integers. In scalar context, only the significand is returned. The significand is the integer with the smallest absolute value. The output of <code>sparts()</code> corresponds to the output from <code>bsstr()</code>.</p>

<p>In Math::BigInt, this method is identical to <code>parts()</code>.</p>

</dd>
<dt id="nparts()"><a class="permalink" href="./Math::BigInt.html#nparts()">#</a><a id="nparts"></a>nparts()</dt>
<dd>

<p>Returns the significand (mantissa) and exponent corresponding to normalized notation. In scalar context, only the significand is returned. For finite non-zero numbers, the significand&#39;s absolute value is greater than or equal to 1 and less than 10. The output of <code>nparts()</code> corresponds to the output from <code>bnstr()</code>. In Math::BigInt, if the significand can not be represented as an integer, upgrading is performed or NaN is returned.</p>

</dd>
<dt id="eparts()"><a class="permalink" href="./Math::BigInt.html#eparts()">#</a><a id="eparts"></a>eparts()</dt>
<dd>

<p>Returns the significand (mantissa) and exponent corresponding to engineering notation. In scalar context, only the significand is returned. For finite non-zero numbers, the significand&#39;s absolute value is greater than or equal to 1 and less than 1000, and the exponent is a multiple of 3. The output of <code>eparts()</code> corresponds to the output from <code>bestr()</code>. In Math::BigInt, if the significand can not be represented as an integer, upgrading is performed or NaN is returned.</p>

</dd>
<dt id="dparts()"><a class="permalink" href="./Math::BigInt.html#dparts()">#</a><a id="dparts"></a>dparts()</dt>
<dd>

<p>Returns the integer part and the fraction part. If the fraction part can not be represented as an integer, upgrading is performed or NaN is returned. The output of <code>dparts()</code> corresponds to the output from <code>bdstr()</code>.</p>

</dd>
</dl>

<h2 id="String-conversion-methods"><a class="permalink" href="./Math::BigInt.html#String-conversion-methods">#</a><a id="String"></a>String conversion methods</h2>

<dl>

<dt id="bstr()"><a class="permalink" href="./Math::BigInt.html#bstr()">#</a><a id="bstr"></a>bstr()</dt>
<dd>

<p>Returns a string representing the number using decimal notation. In Math::BigFloat, the output is zero padded according to the current accuracy or precision, if any of those are defined.</p>

</dd>
<dt id="bsstr()"><a class="permalink" href="./Math::BigInt.html#bsstr()">#</a><a id="bsstr"></a>bsstr()</dt>
<dd>

<p>Returns a string representing the number using scientific notation where both the significand (mantissa) and the exponent are integers. The output corresponds to the output from <code>sparts()</code>.</p>

<pre><code class="plaintext">  123 is returned as &quot;123e+0&quot;
 1230 is returned as &quot;123e+1&quot;
12300 is returned as &quot;123e+2&quot;
12000 is returned as &quot;12e+3&quot;
10000 is returned as &quot;1e+4&quot;</code></pre>

</dd>
<dt id="bnstr()"><a class="permalink" href="./Math::BigInt.html#bnstr()">#</a><a id="bnstr"></a>bnstr()</dt>
<dd>

<p>Returns a string representing the number using normalized notation, the most common variant of scientific notation. For finite non-zero numbers, the absolute value of the significand is greater than or equal to 1 and less than 10. The output corresponds to the output from <code>nparts()</code>.</p>

<pre><code class="plaintext">  123 is returned as &quot;1.23e+2&quot;
 1230 is returned as &quot;1.23e+3&quot;
12300 is returned as &quot;1.23e+4&quot;
12000 is returned as &quot;1.2e+4&quot;
10000 is returned as &quot;1e+4&quot;</code></pre>

</dd>
<dt id="bestr()"><a class="permalink" href="./Math::BigInt.html#bestr()">#</a><a id="bestr"></a>bestr()</dt>
<dd>

<p>Returns a string representing the number using engineering notation. For finite non-zero numbers, the absolute value of the significand is greater than or equal to 1 and less than 1000, and the exponent is a multiple of 3. The output corresponds to the output from <code>eparts()</code>.</p>

<pre><code class="plaintext">  123 is returned as &quot;123e+0&quot;
 1230 is returned as &quot;1.23e+3&quot;
12300 is returned as &quot;12.3e+3&quot;
12000 is returned as &quot;12e+3&quot;
10000 is returned as &quot;10e+3&quot;</code></pre>

</dd>
<dt id="bdstr()"><a class="permalink" href="./Math::BigInt.html#bdstr()">#</a><a id="bdstr"></a>bdstr()</dt>
<dd>

<p>Returns a string representing the number using decimal notation. The output corresponds to the output from <code>dparts()</code>.</p>

<pre><code class="plaintext">  123 is returned as &quot;123&quot;
 1230 is returned as &quot;1230&quot;
12300 is returned as &quot;12300&quot;
12000 is returned as &quot;12000&quot;
10000 is returned as &quot;10000&quot;</code></pre>

</dd>
<dt id="to_hex()"><a class="permalink" href="./Math::BigInt.html#to_hex()">#</a><a id="to_hex"></a>to_hex()</dt>
<dd>

<pre><code>$x-&gt;to_hex();</code></pre>

<p>Returns a hexadecimal string representation of the number. See also from_hex().</p>

</dd>
<dt id="to_bin()"><a class="permalink" href="./Math::BigInt.html#to_bin()">#</a><a id="to_bin"></a>to_bin()</dt>
<dd>

<pre><code>$x-&gt;to_bin();</code></pre>

<p>Returns a binary string representation of the number. See also from_bin().</p>

</dd>
<dt id="to_oct()"><a class="permalink" href="./Math::BigInt.html#to_oct()">#</a><a id="to_oct"></a>to_oct()</dt>
<dd>

<pre><code>$x-&gt;to_oct();</code></pre>

<p>Returns an octal string representation of the number. See also from_oct().</p>

</dd>
<dt id="to_bytes()"><a class="permalink" href="./Math::BigInt.html#to_bytes()">#</a><a id="to_bytes"></a>to_bytes()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;new(&quot;1667327589&quot;);
$s = $x-&gt;to_bytes();                    # $s = &quot;cafe&quot;</code></pre>

<p>Returns a byte string representation of the number using big endian byte order. The invocand must be a non-negative, finite integer. See also from_bytes().</p>

</dd>
<dt id="to_base()"><a class="permalink" href="./Math::BigInt.html#to_base()">#</a><a id="to_base"></a>to_base()</dt>
<dd>

<pre><code>$x = Math::BigInt-&gt;new(&quot;250&quot;);
$x-&gt;to_base(2);     # returns &quot;11111010&quot;
$x-&gt;to_base(8);     # returns &quot;372&quot;
$x-&gt;to_base(16);    # returns &quot;fa&quot;</code></pre>

<p>Returns a string representation of the number in the given base. If a collation sequence is given, the collation sequence determines which characters are used in the output.</p>

<p>Here are some more examples</p>

<pre><code>$x = Math::BigInt-&gt;new(&quot;16&quot;)-&gt;to_base(3);       # returns &quot;121&quot;
$x = Math::BigInt-&gt;new(&quot;44027&quot;)-&gt;to_base(36);   # returns &quot;XYZ&quot;
$x = Math::BigInt-&gt;new(&quot;58314&quot;)-&gt;to_base(42);   # returns &quot;Why&quot;
$x = Math::BigInt-&gt;new(&quot;4&quot;)-&gt;to_base(2, &quot;-|&quot;);  # returns &quot;|--&quot;</code></pre>

<p>See from_base() for information and examples.</p>

</dd>
<dt id="as_hex()"><a class="permalink" href="./Math::BigInt.html#as_hex()">#</a><a id="as_hex"></a>as_hex()</dt>
<dd>

<pre><code>$x-&gt;as_hex();</code></pre>

<p>As, <code>to_hex()</code>, but with a &quot;0x&quot; prefix.</p>

</dd>
<dt id="as_bin()"><a class="permalink" href="./Math::BigInt.html#as_bin()">#</a><a id="as_bin"></a>as_bin()</dt>
<dd>

<pre><code>$x-&gt;as_bin();</code></pre>

<p>As, <code>to_bin()</code>, but with a &quot;0b&quot; prefix.</p>

</dd>
<dt id="as_oct()"><a class="permalink" href="./Math::BigInt.html#as_oct()">#</a><a id="as_oct"></a>as_oct()</dt>
<dd>

<pre><code>$x-&gt;as_oct();</code></pre>

<p>As, <code>to_oct()</code>, but with a &quot;0&quot; prefix.</p>

</dd>
<dt id="as_bytes()"><a class="permalink" href="./Math::BigInt.html#as_bytes()">#</a><a id="as_bytes"></a>as_bytes()</dt>
<dd>

<p>This is just an alias for <code>to_bytes()</code>.</p>

</dd>
</dl>

<h2 id="Other-conversion-methods"><a class="permalink" href="./Math::BigInt.html#Other-conversion-methods">#</a><a id="Other1"></a>Other conversion methods</h2>

<dl>

<dt id="numify()"><a class="permalink" href="./Math::BigInt.html#numify()">#</a><a id="numify"></a>numify()</dt>
<dd>

<pre><code>print $x-&gt;numify();</code></pre>

<p>Returns a Perl scalar from $x. It is used automatically whenever a scalar is needed, for instance in array index operations.</p>

</dd>
</dl>

<h1 id="ACCURACY-and-PRECISION"><a class="permalink" href="./Math::BigInt.html#ACCURACY-and-PRECISION">#</a><a id="ACCURACY"></a>ACCURACY and PRECISION</h1>

<p>Math::BigInt and Math::BigFloat have full support for accuracy and precision based rounding, both automatically after every operation, as well as manually.</p>

<p>This section describes the accuracy/precision handling in Math::BigInt and Math::BigFloat as it used to be and as it is now, complete with an explanation of all terms and abbreviations.</p>

<p>Not yet implemented things (but with correct description) are marked with &#39;!&#39;, things that need to be answered are marked with &#39;?&#39;.</p>

<p>In the next paragraph follows a short description of terms used here (because these may differ from terms used by others people or documentation).</p>

<p>During the rest of this document, the shortcuts A (for accuracy), P (for precision), F (fallback) and R (rounding mode) are be used.</p>

<h2 id="Precision-P"><a class="permalink" href="./Math::BigInt.html#Precision-P">#</a><a id="Precision1"></a>Precision P</h2>

<p>Precision is a fixed number of digits before (positive) or after (negative) the decimal point. For example, 123.45 has a precision of -2. 0 means an integer like 123 (or 120). A precision of 2 means at least two digits to the left of the decimal point are zero, so 123 with P = 1 becomes 120. Note that numbers with zeros before the decimal point may have different precisions, because 1200 can have P = 0, 1 or 2 (depending on what the initial value was). It could also have p &lt; 0, when the digits after the decimal point are zero.</p>

<p>The string output (of floating point numbers) is padded with zeros:</p>

<pre><code class="plaintext">Initial value    P      A       Result          String
------------------------------------------------------------
1234.01         -3              1000            1000
1234            -2              1200            1200
1234.5          -1              1230            1230
1234.001         1              1234            1234.0
1234.01          0              1234            1234
1234.01          2              1234.01         1234.01
1234.01          5              1234.01         1234.01000</code></pre>

<p>For Math::BigInt objects, no padding occurs.</p>

<h2 id="Accuracy-A"><a class="permalink" href="./Math::BigInt.html#Accuracy-A">#</a><a id="Accuracy"></a>Accuracy A</h2>

<p>Number of significant digits. Leading zeros are not counted. A number may have an accuracy greater than the non-zero digits when there are zeros in it or trailing zeros. For example, 123.456 has A of 6, 10203 has 5, 123.0506 has 7, 123.45000 has 8 and 0.000123 has 3.</p>

<p>The string output (of floating point numbers) is padded with zeros:</p>

<pre><code class="plaintext">Initial value    P      A       Result          String
------------------------------------------------------------
1234.01                 3       1230            1230
1234.01                 6       1234.01         1234.01
1234.1                  8       1234.1          1234.1000</code></pre>

<p>For Math::BigInt objects, no padding occurs.</p>

<h2 id="Fallback-F"><a class="permalink" href="./Math::BigInt.html#Fallback-F">#</a><a id="Fallback"></a>Fallback F</h2>

<p>When both A and P are undefined, this is used as a fallback accuracy when dividing numbers.</p>

<h2 id="Rounding-mode-R"><a class="permalink" href="./Math::BigInt.html#Rounding-mode-R">#</a><a id="Rounding2"></a>Rounding mode R</h2>

<p>When rounding a number, different &#39;styles&#39; or &#39;kinds&#39; of rounding are possible. (Note that random rounding, as in Math::Round, is not implemented.)</p>

<h3 id="Directed-rounding"><a class="permalink" href="./Math::BigInt.html#Directed-rounding">#</a><a id="Directed"></a>Directed rounding</h3>

<p>These round modes always round in the same direction.</p>

<dl>

<dt id="&#39;trunc&#39;"><a class="permalink" href="./Math::BigInt.html#&#39;trunc&#39;">#</a><a id="trunc"></a>&#39;trunc&#39;</dt>
<dd>

<p>Round towards zero. Remove all digits following the rounding place, i.e., replace them with zeros. Thus, 987.65 rounded to tens (P=1) becomes 980, and rounded to the fourth significant digit becomes 987.6 (A=4). 123.456 rounded to the second place after the decimal point (P=-2) becomes 123.46. This corresponds to the IEEE 754 rounding mode &#39;roundTowardZero&#39;.</p>

</dd>
</dl>

<h3 id="Rounding-to-nearest"><a class="permalink" href="./Math::BigInt.html#Rounding-to-nearest">#</a><a id="Rounding3"></a>Rounding to nearest</h3>

<p>These rounding modes round to the nearest digit. They differ in how they determine which way to round in the ambiguous case when there is a tie.</p>

<dl>

<dt id="&#39;even&#39;"><a class="permalink" href="./Math::BigInt.html#&#39;even&#39;">#</a><a id="even"></a>&#39;even&#39;</dt>
<dd>

<p>Round towards the nearest even digit, e.g., when rounding to nearest integer, -5.5 becomes -6, 4.5 becomes 4, but 4.501 becomes 5. This corresponds to the IEEE 754 rounding mode &#39;roundTiesToEven&#39;.</p>

</dd>
<dt id="&#39;odd&#39;"><a class="permalink" href="./Math::BigInt.html#&#39;odd&#39;">#</a><a id="odd"></a>&#39;odd&#39;</dt>
<dd>

<p>Round towards the nearest odd digit, e.g., when rounding to nearest integer, 4.5 becomes 5, -5.5 becomes -5, but 5.501 becomes 6. This corresponds to the IEEE 754 rounding mode &#39;roundTiesToOdd&#39;.</p>

</dd>
<dt id="&#39;+inf&#39;"><a class="permalink" href="./Math::BigInt.html#&#39;+inf&#39;">#</a><a id="inf"></a>&#39;+inf&#39;</dt>
<dd>

<p>Round towards plus infinity, i.e., always round up. E.g., when rounding to the nearest integer, 4.5 becomes 5, -5.5 becomes -5, and 4.501 also becomes 5. This corresponds to the IEEE 754 rounding mode &#39;roundTiesToPositive&#39;.</p>

</dd>
<dt id="&#39;-inf&#39;"><a class="permalink" href="./Math::BigInt.html#&#39;-inf&#39;">#</a><a id="inf1"></a>&#39;-inf&#39;</dt>
<dd>

<p>Round towards minus infinity, i.e., always round down. E.g., when rounding to the nearest integer, 4.5 becomes 4, -5.5 becomes -6, but 4.501 becomes 5. This corresponds to the IEEE 754 rounding mode &#39;roundTiesToNegative&#39;.</p>

</dd>
<dt id="&#39;zero&#39;"><a class="permalink" href="./Math::BigInt.html#&#39;zero&#39;">#</a><a id="zero"></a>&#39;zero&#39;</dt>
<dd>

<p>Round towards zero, i.e., round positive numbers down and negative numbers up. E.g., when rounding to the nearest integer, 4.5 becomes 4, -5.5 becomes -5, but 4.501 becomes 5. This corresponds to the IEEE 754 rounding mode &#39;roundTiesToZero&#39;.</p>

</dd>
<dt id="&#39;common&#39;"><a class="permalink" href="./Math::BigInt.html#&#39;common&#39;">#</a><a id="common"></a>&#39;common&#39;</dt>
<dd>

<p>Round away from zero, i.e., round to the number with the largest absolute value. E.g., when rounding to the nearest integer, -1.5 becomes -2, 1.5 becomes 2 and 1.49 becomes 1. This corresponds to the IEEE 754 rounding mode &#39;roundTiesToAway&#39;.</p>

</dd>
</dl>

<p>The handling of A &amp; P in MBI/MBF (the old core code shipped with Perl versions &lt;= 5.7.2) is like this:</p>

<dl>

<dt id="Precision"><a class="permalink" href="./Math::BigInt.html#Precision">#</a>Precision</dt>
<dd>

<pre><code>* bfround($p) is able to round to $p number of digits after the decimal
  point
* otherwise P is unused</code></pre>

</dd>
<dt id="Accuracy-(significant-digits)"><a class="permalink" href="./Math::BigInt.html#Accuracy-(significant-digits)">#</a><a id="Accuracy1"></a><a id="Accuracy-significant-digits"></a>Accuracy (significant digits)</dt>
<dd>

<pre><code> * bround($a) rounds to $a significant digits
 * only bdiv() and bsqrt() take A as (optional) parameter
   + other operations simply create the same number (bneg etc), or
     more (bmul) of digits
   + rounding/truncating is only done when explicitly calling one
     of bround or bfround, and never for Math::BigInt (not implemented)
 * bsqrt() simply hands its accuracy argument over to bdiv.
 * the documentation and the comment in the code indicate two
   different ways on how bdiv() determines the maximum number
   of digits it should calculate, and the actual code does yet
   another thing
   POD:
     max($Math::BigFloat::div_scale,length(dividend)+length(divisor))
   Comment:
     result has at most max(scale, length(dividend), length(divisor)) digits
   Actual code:
     scale = max(scale, length(dividend)-1,length(divisor)-1);
     scale += length(divisor) - length(dividend);
   So for lx = 3, ly = 9, scale = 10, scale will actually be 16 (10
   So for lx = 3, ly = 9, scale = 10, scale will actually be 16
   (10+9-3). Actually, the &#39;difference&#39; added to the scale is cal-
   culated from the number of &quot;significant digits&quot; in dividend and
   divisor, which is derived by looking at the length of the man-
   tissa. Which is wrong, since it includes the + sign (oops) and
   actually gets 2 for &#39;+100&#39; and 4 for &#39;+101&#39;. Oops again. Thus
   124/3 with div_scale=1 will get you &#39;41.3&#39; based on the strange
   assumption that 124 has 3 significant digits, while 120/7 will
   get you &#39;17&#39;, not &#39;17.1&#39; since 120 is thought to have 2 signif-
   icant digits. The rounding after the division then uses the
   remainder and $y to determine whether it must round up or down.
?  I have no idea which is the right way. That&#39;s why I used a slightly more
?  simple scheme and tweaked the few failing testcases to match it.</code></pre>

</dd>
</dl>

<p>This is how it works now:</p>

<dl>

<dt id="Setting/Accessing"><a class="permalink" href="./Math::BigInt.html#Setting/Accessing">#</a><a id="Setting"></a><a id="Setting-Accessing"></a>Setting/Accessing</dt>
<dd>

<pre><code>* You can set the A global via Math::BigInt-&gt;accuracy() or
  Math::BigFloat-&gt;accuracy() or whatever class you are using.
* You can also set P globally by using Math::SomeClass-&gt;precision()
  likewise.
* Globals are classwide, and not inherited by subclasses.
* to undefine A, use Math::SomeCLass-&gt;accuracy(undef);
* to undefine P, use Math::SomeClass-&gt;precision(undef);
* Setting Math::SomeClass-&gt;accuracy() clears automatically
  Math::SomeClass-&gt;precision(), and vice versa.
* To be valid, A must be &gt; 0, P can have any value.
* If P is negative, this means round to the P&#39;th place to the right of the
  decimal point; positive values mean to the left of the decimal point.
  P of 0 means round to integer.
* to find out the current global A, use Math::SomeClass-&gt;accuracy()
* to find out the current global P, use Math::SomeClass-&gt;precision()
* use $x-&gt;accuracy() respective $x-&gt;precision() for the local
  setting of $x.
* Please note that $x-&gt;accuracy() respective $x-&gt;precision()
  return eventually defined global A or P, when $x&#39;s A or P is not
  set.</code></pre>

</dd>
<dt id="Creating-numbers"><a class="permalink" href="./Math::BigInt.html#Creating-numbers">#</a><a id="Creating"></a>Creating numbers</dt>
<dd>

<pre><code>* When you create a number, you can give the desired A or P via:
  $x = Math::BigInt-&gt;new($number,$A,$P);
* Only one of A or P can be defined, otherwise the result is NaN
* If no A or P is give ($x = Math::BigInt-&gt;new($number) form), then the
  globals (if set) will be used. Thus changing the global defaults later on
  will not change the A or P of previously created numbers (i.e., A and P of
  $x will be what was in effect when $x was created)
* If given undef for A and P, NO rounding will occur, and the globals will
  NOT be used. This is used by subclasses to create numbers without
  suffering rounding in the parent. Thus a subclass is able to have its own
  globals enforced upon creation of a number by using
  $x = Math::BigInt-&gt;new($number,undef,undef):

      use Math::BigInt::SomeSubclass;
      use Math::BigInt;

      Math::BigInt-&gt;accuracy(2);
      Math::BigInt::SomeSubClass-&gt;accuracy(3);
      $x = Math::BigInt::SomeSubClass-&gt;new(1234);

  $x is now 1230, and not 1200. A subclass might choose to implement
  this otherwise, e.g. falling back to the parent&#39;s A and P.</code></pre>

</dd>
<dt id="Usage"><a class="permalink" href="./Math::BigInt.html#Usage">#</a>Usage</dt>
<dd>

<pre><code class="plaintext">* If A or P are enabled/defined, they are used to round the result of each
  operation according to the rules below
* Negative P is ignored in Math::BigInt, since Math::BigInt objects never
  have digits after the decimal point
* Math::BigFloat uses Math::BigInt internally, but setting A or P inside
  Math::BigInt as globals does not tamper with the parts of a Math::BigFloat.
  A flag is used to mark all Math::BigFloat numbers as &#39;never round&#39;.</code></pre>

</dd>
<dt id="Precedence"><a class="permalink" href="./Math::BigInt.html#Precedence">#</a>Precedence</dt>
<dd>

<pre><code> * It only makes sense that a number has only one of A or P at a time.
   If you set either A or P on one object, or globally, the other one will
   be automatically cleared.
 * If two objects are involved in an operation, and one of them has A in
   effect, and the other P, this results in an error (NaN).
 * A takes precedence over P (Hint: A comes before P).
   If neither of them is defined, nothing is used, i.e. the result will have
   as many digits as it can (with an exception for bdiv/bsqrt) and will not
   be rounded.
 * There is another setting for bdiv() (and thus for bsqrt()). If neither of
   A or P is defined, bdiv() will use a fallback (F) of $div_scale digits.
   If either the dividend&#39;s or the divisor&#39;s mantissa has more digits than
   the value of F, the higher value will be used instead of F.
   This is to limit the digits (A) of the result (just consider what would
   happen with unlimited A and P in the case of 1/3 :-)
 * bdiv will calculate (at least) 4 more digits than required (determined by
   A, P or F), and, if F is not used, round the result
   (this will still fail in the case of a result like 0.12345000000001 with A
   or P of 5, but this can not be helped - or can it?)
 * Thus you can have the math done by on Math::Big* class in two modi:
   + never round (this is the default):
     This is done by setting A and P to undef. No math operation
     will round the result, with bdiv() and bsqrt() as exceptions to guard
     against overflows. You must explicitly call bround(), bfround() or
     round() (the latter with parameters).
     Note: Once you have rounded a number, the settings will &#39;stick&#39; on it
     and &#39;infect&#39; all other numbers engaged in math operations with it, since
     local settings have the highest precedence. So, to get SaferRound[tm],
     use a copy() before rounding like this:

       $x = Math::BigFloat-&gt;new(12.34);
       $y = Math::BigFloat-&gt;new(98.76);
       $z = $x * $y;                           # 1218.6984
       print $x-&gt;copy()-&gt;bround(3);            # 12.3 (but A is now 3!)
       $z = $x * $y;                           # still 1218.6984, without
                                               # copy would have been 1210!

   + round after each op:
     After each single operation (except for testing like is_zero()), the
     method round() is called and the result is rounded appropriately. By
     setting proper values for A and P, you can have all-the-same-A or
     all-the-same-P modes. For example, Math::Currency might set A to undef,
     and P to -2, globally.

?Maybe an extra option that forbids local A &amp; P settings would be in order,
?so that intermediate rounding does not &#39;poison&#39; further math?</code></pre>

</dd>
<dt id="Overriding-globals"><a class="permalink" href="./Math::BigInt.html#Overriding-globals">#</a><a id="Overriding"></a>Overriding globals</dt>
<dd>

<pre><code class="plaintext">* you will be able to give A, P and R as an argument to all the calculation
  routines; the second parameter is A, the third one is P, and the fourth is
  R (shift right by one for binary operations like badd). P is used only if
  the first parameter (A) is undefined. These three parameters override the
  globals in the order detailed as follows, i.e. the first defined value
  wins:
  (local: per object, global: global default, parameter: argument to sub)
    + parameter A
    + parameter P
    + local A (if defined on both of the operands: smaller one is taken)
    + local P (if defined on both of the operands: bigger one is taken)
    + global A
    + global P
    + global F
* bsqrt() will hand its arguments to bdiv(), as it used to, only now for two
  arguments (A and P) instead of one</code></pre>

</dd>
<dt id="Local-settings"><a class="permalink" href="./Math::BigInt.html#Local-settings">#</a><a id="Local"></a>Local settings</dt>
<dd>

<pre><code>* You can set A or P locally by using $x-&gt;accuracy() or
  $x-&gt;precision()
  and thus force different A and P for different objects/numbers.
* Setting A or P this way immediately rounds $x to the new value.
* $x-&gt;accuracy() clears $x-&gt;precision(), and vice versa.</code></pre>

</dd>
<dt id="Rounding"><a class="permalink" href="./Math::BigInt.html#Rounding">#</a>Rounding</dt>
<dd>

<pre><code>* the rounding routines will use the respective global or local settings.
  bround() is for accuracy rounding, while bfround() is for precision
* the two rounding functions take as the second parameter one of the
  following rounding modes (R):
  &#39;even&#39;, &#39;odd&#39;, &#39;+inf&#39;, &#39;-inf&#39;, &#39;zero&#39;, &#39;trunc&#39;, &#39;common&#39;
* you can set/get the global R by using Math::SomeClass-&gt;round_mode()
  or by setting $Math::SomeClass::round_mode
* after each operation, $result-&gt;round() is called, and the result may
  eventually be rounded (that is, if A or P were set either locally,
  globally or as parameter to the operation)
* to manually round a number, call $x-&gt;round($A,$P,$round_mode);
  this will round the number by using the appropriate rounding function
  and then normalize it.
* rounding modifies the local settings of the number:

      $x = Math::BigFloat-&gt;new(123.456);
      $x-&gt;accuracy(5);
      $x-&gt;bround(4);

  Here 4 takes precedence over 5, so 123.5 is the result and $x-&gt;accuracy()
  will be 4 from now on.</code></pre>

</dd>
<dt id="Default-values"><a class="permalink" href="./Math::BigInt.html#Default-values">#</a><a id="Default"></a>Default values</dt>
<dd>

<pre><code class="plaintext">* R: &#39;even&#39;
* F: 40
* A: undef
* P: undef</code></pre>

</dd>
<dt id="Remarks"><a class="permalink" href="./Math::BigInt.html#Remarks">#</a>Remarks</dt>
<dd>

<pre><code class="plaintext">* The defaults are set up so that the new code gives the same results as
  the old code (except in a few cases on bdiv):
  + Both A and P are undefined and thus will not be used for rounding
    after each operation.
  + round() is thus a no-op, unless given extra parameters A and P</code></pre>

</dd>
</dl>

<h1 id="Infinity-and-Not-a-Number"><a class="permalink" href="./Math::BigInt.html#Infinity-and-Not-a-Number">#</a><a id="Infinity"></a>Infinity and Not a Number</h1>

<p>While Math::BigInt has extensive handling of inf and NaN, certain quirks remain.</p>

<dl>

<dt id="oct()/hex()"><a class="permalink" href="./Math::BigInt.html#oct()/hex()">#</a><a id="oct"></a><a id="oct-hex"></a>oct()/hex()</dt>
<dd>

<p>These perl routines currently (as of Perl v.5.8.6) cannot handle passed inf.</p>

<pre><code>te@linux:~&gt; perl -wle &#39;print 2 ** 3333&#39;
Inf
te@linux:~&gt; perl -wle &#39;print 2 ** 3333 == 2 ** 3333&#39;
1
te@linux:~&gt; perl -wle &#39;print oct(2 ** 3333)&#39;
0
te@linux:~&gt; perl -wle &#39;print hex(2 ** 3333)&#39;
Illegal hexadecimal digit &#39;I&#39; ignored at -e line 1.
0</code></pre>

<p>The same problems occur if you pass them Math::BigInt-&gt;binf() objects. Since overloading these routines is not possible, this cannot be fixed from Math::BigInt.</p>

</dd>
</dl>

<h1 id="INTERNALS"><a class="permalink" href="./Math::BigInt.html#INTERNALS">#</a>INTERNALS</h1>

<p>You should neither care about nor depend on the internal representation; it might change without notice. Use <b>ONLY</b> method calls like <code>$x-&gt;sign();</code> instead relying on the internal representation.</p>

<h2 id="MATH-LIBRARY"><a class="permalink" href="./Math::BigInt.html#MATH-LIBRARY">#</a><a id="MATH"></a>MATH LIBRARY</h2>

<p>Math with the numbers is done (by default) by a module called <code>Math::BigInt::Calc</code>. This is equivalent to saying:</p>

<pre><code>use Math::BigInt try =&gt; &#39;Calc&#39;;</code></pre>

<p>You can change this backend library by using:</p>

<pre><code>use Math::BigInt try =&gt; &#39;GMP&#39;;</code></pre>

<p><b>Note</b>: General purpose packages should not be explicit about the library to use; let the script author decide which is best.</p>

<p>If your script works with huge numbers and Calc is too slow for them, you can also for the loading of one of these libraries and if none of them can be used, the code dies:</p>

<pre><code>use Math::BigInt only =&gt; &#39;GMP,Pari&#39;;</code></pre>

<p>The following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:</p>

<pre><code>use Math::BigInt try =&gt; &#39;Foo,Math::BigInt::Bar&#39;;</code></pre>

<p>The library that is loaded last is used. Note that this can be overwritten at any time by loading a different library, and numbers constructed with different libraries cannot be used in math operations together.</p>

<h3 id="What-library-to-use?"><a class="permalink" href="./Math::BigInt.html#What-library-to-use?">#</a><a id="What"></a><a id="What-library-to-use"></a>What library to use?</h3>

<p><b>Note</b>: General purpose packages should not be explicit about the library to use; let the script author decide which is best.</p>

<p><a href="./Math::BigInt::GMP.html">Math::BigInt::GMP</a> and <a href="./Math::BigInt::Pari.html">Math::BigInt::Pari</a> are in cases involving big numbers much faster than Calc, however it is slower when dealing with very small numbers (less than about 20 digits) and when converting very large numbers to decimal (for instance for printing, rounding, calculating their length in decimal etc).</p>

<p>So please select carefully what library you want to use.</p>

<p>Different low-level libraries use different formats to store the numbers. However, you should <b>NOT</b> depend on the number having a specific format internally.</p>

<p>See the respective math library module documentation for further details.</p>

<h2 id="SIGN"><a class="permalink" href="./Math::BigInt.html#SIGN">#</a>SIGN</h2>

<p>The sign is either &#39;+&#39;, &#39;-&#39;, &#39;NaN&#39;, &#39;+inf&#39; or &#39;-inf&#39;.</p>

<p>A sign of &#39;NaN&#39; is used to represent the result when input arguments are not numbers or as a result of 0/0. &#39;+inf&#39; and &#39;-inf&#39; represent plus respectively minus infinity. You get &#39;+inf&#39; when dividing a positive number by 0, and &#39;-inf&#39; when dividing any negative number by 0.</p>

<h1 id="EXAMPLES"><a class="permalink" href="./Math::BigInt.html#EXAMPLES">#</a>EXAMPLES</h1>

<pre><code>use Math::BigInt;

sub bigint { Math::BigInt-&gt;new(shift); }

$x = Math::BigInt-&gt;bstr(&quot;1234&quot;)       # string &quot;1234&quot;
$x = &quot;$x&quot;;                            # same as bstr()
$x = Math::BigInt-&gt;bneg(&quot;1234&quot;);      # Math::BigInt &quot;-1234&quot;
$x = Math::BigInt-&gt;babs(&quot;-12345&quot;);    # Math::BigInt &quot;12345&quot;
$x = Math::BigInt-&gt;bnorm(&quot;-0.00&quot;);    # Math::BigInt &quot;0&quot;
$x = bigint(1) + bigint(2);           # Math::BigInt &quot;3&quot;
$x = bigint(1) + &quot;2&quot;;                 # ditto (auto-Math::BigIntify of &quot;2&quot;)
$x = bigint(1);                       # Math::BigInt &quot;1&quot;
$x = $x + 5 / 2;                      # Math::BigInt &quot;3&quot;
$x = $x ** 3;                         # Math::BigInt &quot;27&quot;
$x *= 2;                              # Math::BigInt &quot;54&quot;
$x = Math::BigInt-&gt;new(0);            # Math::BigInt &quot;0&quot;
$x--;                                 # Math::BigInt &quot;-1&quot;
$x = Math::BigInt-&gt;badd(4,5)          # Math::BigInt &quot;9&quot;
print $x-&gt;bsstr();                    # 9e+0</code></pre>

<p>Examples for rounding:</p>

<pre><code>use Math::BigFloat;
use Test::More;

$x = Math::BigFloat-&gt;new(123.4567);
$y = Math::BigFloat-&gt;new(123.456789);
Math::BigFloat-&gt;accuracy(4);          # no more A than 4

is ($x-&gt;copy()-&gt;bround(),123.4);      # even rounding
print $x-&gt;copy()-&gt;bround(),&quot;\n&quot;;      # 123.4
Math::BigFloat-&gt;round_mode(&#39;odd&#39;);    # round to odd
print $x-&gt;copy()-&gt;bround(),&quot;\n&quot;;      # 123.5
Math::BigFloat-&gt;accuracy(5);          # no more A than 5
Math::BigFloat-&gt;round_mode(&#39;odd&#39;);    # round to odd
print $x-&gt;copy()-&gt;bround(),&quot;\n&quot;;      # 123.46
$y = $x-&gt;copy()-&gt;bround(4),&quot;\n&quot;;      # A = 4: 123.4
print &quot;$y, &quot;,$y-&gt;accuracy(),&quot;\n&quot;;     # 123.4, 4

Math::BigFloat-&gt;accuracy(undef);      # A not important now
Math::BigFloat-&gt;precision(2);         # P important
print $x-&gt;copy()-&gt;bnorm(),&quot;\n&quot;;       # 123.46
print $x-&gt;copy()-&gt;bround(),&quot;\n&quot;;      # 123.46</code></pre>

<p>Examples for converting:</p>

<pre><code>my $x = Math::BigInt-&gt;new(&#39;0b1&#39;.&#39;01&#39; x 123);
print &quot;bin: &quot;,$x-&gt;as_bin(),&quot; hex:&quot;,$x-&gt;as_hex(),&quot; dec: &quot;,$x,&quot;\n&quot;;</code></pre>

<h1 id="Autocreating-constants"><a class="permalink" href="./Math::BigInt.html#Autocreating-constants">#</a><a id="Autocreating"></a>Autocreating constants</h1>

<p>After <code>use Math::BigInt &#39;:constant&#39;</code> all the <b>integer</b> decimal, hexadecimal and binary constants in the given scope are converted to <code>Math::BigInt</code>. This conversion happens at compile time.</p>

<p>In particular,</p>

<pre><code class="plaintext">perl -MMath::BigInt=:constant -e &#39;print 2**100,&quot;\n&quot;&#39;</code></pre>

<p>prints the integer value of <code>2**100</code>. Note that without conversion of constants the expression 2**100 is calculated using Perl scalars.</p>

<p>Please note that strings and floating point constants are not affected, so that</p>

<pre><code>use Math::BigInt qw/:constant/;

$x = 1234567890123456789012345678901234567890
        + 123456789123456789;
$y = &#39;1234567890123456789012345678901234567890&#39;
        + &#39;123456789123456789&#39;;</code></pre>

<p>does not give you what you expect. You need an explicit Math::BigInt-&gt;new() around one of the operands. You should also quote large constants to protect loss of precision:</p>

<pre><code>use Math::BigInt;

$x = Math::BigInt-&gt;new(&#39;1234567889123456789123456789123456789&#39;);</code></pre>

<p>Without the quotes Perl would convert the large number to a floating point constant at compile time and then hand the result to Math::BigInt, which results in an truncated result or a NaN.</p>

<p>This also applies to integers that look like floating point constants:</p>

<pre><code>use Math::BigInt &#39;:constant&#39;;

print ref(123e2),&quot;\n&quot;;
print ref(123.2e2),&quot;\n&quot;;</code></pre>

<p>prints nothing but newlines. Use either <a href="bignum.html">bignum</a> or <a href="./Math::BigFloat.html">Math::BigFloat</a> to get this to work.</p>

<h1 id="PERFORMANCE"><a class="permalink" href="./Math::BigInt.html#PERFORMANCE">#</a>PERFORMANCE</h1>

<p>Using the form $x += $y; etc over $x = $x + $y is faster, since a copy of $x must be made in the second case. For long numbers, the copy can eat up to 20% of the work (in the case of addition/subtraction, less for multiplication/division). If $y is very small compared to $x, the form $x += $y is MUCH faster than $x = $x + $y since making the copy of $x takes more time then the actual addition.</p>

<p>With a technique called copy-on-write, the cost of copying with overload could be minimized or even completely avoided. A test implementation of COW did show performance gains for overloaded math, but introduced a performance loss due to a constant overhead for all other operations. So Math::BigInt does currently not COW.</p>

<p>The rewritten version of this module (vs. v0.01) is slower on certain operations, like <code>new()</code>, <code>bstr()</code> and <code>numify()</code>. The reason are that it does now more work and handles much more cases. The time spent in these operations is usually gained in the other math operations so that code on the average should get (much) faster. If they don&#39;t, please contact the author.</p>

<p>Some operations may be slower for small numbers, but are significantly faster for big numbers. Other operations are now constant (O(1), like <code>bneg()</code>, <code>babs()</code> etc), instead of O(N) and thus nearly always take much less time. These optimizations were done on purpose.</p>

<p>If you find the Calc module to slow, try to install any of the replacement modules and see if they help you.</p>

<h2 id="Alternative-math-libraries"><a class="permalink" href="./Math::BigInt.html#Alternative-math-libraries">#</a><a id="Alternative"></a>Alternative math libraries</h2>

<p>You can use an alternative library to drive Math::BigInt. See the section <a href="./Math::BigInt.html#MATH-LIBRARY">&quot;MATH LIBRARY&quot;</a> for more information.</p>

<p>For more benchmark results see <a href="http://bloodgate.com/perl/benchmarks.html">http://bloodgate.com/perl/benchmarks.html</a>.</p>

<h1 id="SUBCLASSING"><a class="permalink" href="./Math::BigInt.html#SUBCLASSING">#</a>SUBCLASSING</h1>

<h2 id="Subclassing-Math::BigInt"><a class="permalink" href="./Math::BigInt.html#Subclassing-Math::BigInt">#</a><a id="Subclassing"></a>Subclassing Math::BigInt</h2>

<p>The basic design of Math::BigInt allows simple subclasses with very little work, as long as a few simple rules are followed:</p>

<ul>

<li><p>The public API must remain consistent, i.e. if a sub-class is overloading addition, the sub-class must use the same name, in this case badd(). The reason for this is that Math::BigInt is optimized to call the object methods directly.</p>

</li>
<li><p>The private object hash keys like <code>$x-&gt;{sign}</code> may not be changed, but additional keys can be added, like <code>$x-&gt;{_custom}</code>.</p>

</li>
<li><p>Accessor functions are available for all existing object hash keys and should be used instead of directly accessing the internal hash keys. The reason for this is that Math::BigInt itself has a pluggable interface which permits it to support different storage methods.</p>

</li>
</ul>

<p>More complex sub-classes may have to replicate more of the logic internal of Math::BigInt if they need to change more basic behaviors. A subclass that needs to merely change the output only needs to overload <code>bstr()</code>.</p>

<p>All other object methods and overloaded functions can be directly inherited from the parent class.</p>

<p>At the very minimum, any subclass needs to provide its own <code>new()</code> and can store additional hash keys in the object. There are also some package globals that must be defined, e.g.:</p>

<pre><code># Globals
$accuracy = undef;
$precision = -2;       # round to 2 decimal places
$round_mode = &#39;even&#39;;
$div_scale = 40;</code></pre>

<p>Additionally, you might want to provide the following two globals to allow auto-upgrading and auto-downgrading to work correctly:</p>

<pre><code>$upgrade = undef;
$downgrade = undef;</code></pre>

<p>This allows Math::BigInt to correctly retrieve package globals from the subclass, like <code>$SubClass::precision</code>. See t/Math/BigInt/Subclass.pm or t/Math/BigFloat/SubClass.pm completely functional subclass examples.</p>

<p>Don&#39;t forget to</p>

<pre><code>use overload;</code></pre>

<p>in your subclass to automatically inherit the overloading from the parent. If you like, you can change part of the overloading, look at Math::String for an example.</p>

<h1 id="UPGRADING"><a class="permalink" href="./Math::BigInt.html#UPGRADING">#</a>UPGRADING</h1>

<p>When used like this:</p>

<pre><code>use Math::BigInt upgrade =&gt; &#39;Foo::Bar&#39;;</code></pre>

<p>certain operations &#39;upgrade&#39; their calculation and thus the result to the class Foo::Bar. Usually this is used in conjunction with Math::BigFloat:</p>

<pre><code>use Math::BigInt upgrade =&gt; &#39;Math::BigFloat&#39;;</code></pre>

<p>As a shortcut, you can use the module <a href="bignum.html">bignum</a>:</p>

<pre><code>use bignum;</code></pre>

<p>Also good for one-liners:</p>

<pre><code class="plaintext">perl -Mbignum -le &#39;print 2 ** 255&#39;</code></pre>

<p>This makes it possible to mix arguments of different classes (as in 2.5 + 2) as well es preserve accuracy (as in sqrt(3)).</p>

<p>Beware: This feature is not fully implemented yet.</p>

<h2 id="Auto-upgrade"><a class="permalink" href="./Math::BigInt.html#Auto-upgrade">#</a><a id="Auto"></a>Auto-upgrade</h2>

<p>The following methods upgrade themselves unconditionally; that is if upgrade is in effect, they always hands up their work:</p>

<pre><code class="plaintext">div bsqrt blog bexp bpi bsin bcos batan batan2</code></pre>

<p>All other methods upgrade themselves only when one (or all) of their arguments are of the class mentioned in $upgrade.</p>

<h1 id="EXPORTS"><a class="permalink" href="./Math::BigInt.html#EXPORTS">#</a>EXPORTS</h1>

<p><code>Math::BigInt</code> exports nothing by default, but can export the following methods:</p>

<pre><code class="plaintext">bgcd
blcm</code></pre>

<h1 id="CAVEATS"><a class="permalink" href="./Math::BigInt.html#CAVEATS">#</a>CAVEATS</h1>

<p>Some things might not work as you expect them. Below is documented what is known to be troublesome:</p>

<dl>

<dt id="Comparing-numbers-as-strings"><a class="permalink" href="./Math::BigInt.html#Comparing-numbers-as-strings">#</a><a id="Comparing"></a>Comparing numbers as strings</dt>
<dd>

<p>Both <code>bstr()</code> and <code>bsstr()</code> as well as stringify via overload drop the leading &#39;+&#39;. This is to be consistent with Perl and to make <code>cmp</code> (especially with overloading) to work as you expect. It also solves problems with <code>Test.pm</code> and <a href="./Test::More.html">Test::More</a>, which stringify arguments before comparing them.</p>

<p>Mark Biggar said, when asked about to drop the &#39;+&#39; altogether, or make only <code>cmp</code> work:</p>

<pre><code class="plaintext">I agree (with the first alternative), don&#39;t add the &#39;+&#39; on positive
numbers.  It&#39;s not as important anymore with the new internal form
for numbers.  It made doing things like abs and neg easier, but
those have to be done differently now anyway.</code></pre>

<p>So, the following examples now works as expected:</p>

<pre><code>use Test::More tests =&gt; 1;
use Math::BigInt;

my $x = Math::BigInt -&gt; new(3*3);
my $y = Math::BigInt -&gt; new(3*3);

is($x,3*3, &#39;multiplication&#39;);
print &quot;$x eq 9&quot; if $x eq $y;
print &quot;$x eq 9&quot; if $x eq &#39;9&#39;;
print &quot;$x eq 9&quot; if $x eq 3*3;</code></pre>

<p>Additionally, the following still works:</p>

<pre><code>print &quot;$x == 9&quot; if $x == $y;
print &quot;$x == 9&quot; if $x == 9;
print &quot;$x == 9&quot; if $x == 3*3;</code></pre>

<p>There is now a <code>bsstr()</code> method to get the string in scientific notation aka <code>1e+2</code> instead of <code>100</code>. Be advised that overloaded &#39;eq&#39; always uses bstr() for comparison, but Perl represents some numbers as 100 and others as 1e+308. If in doubt, convert both arguments to Math::BigInt before comparing them as strings:</p>

<pre><code>use Test::More tests =&gt; 3;
use Math::BigInt;

$x = Math::BigInt-&gt;new(&#39;1e56&#39;); $y = 1e56;
is($x,$y);                     # fails
is($x-&gt;bsstr(),$y);            # okay
$y = Math::BigInt-&gt;new($y);
is($x,$y);                     # okay</code></pre>

<p>Alternatively, simply use <code>&lt;=&gt;</code> for comparisons, this always gets it right. There is not yet a way to get a number automatically represented as a string that matches exactly the way Perl represents it.</p>

<p>See also the section about <a href="./Math::BigInt.html#Infinity-and-Not-a-Number">&quot;Infinity and Not a Number&quot;</a> for problems in comparing NaNs.</p>

</dd>
<dt id="int()"><a class="permalink" href="./Math::BigInt.html#int()">#</a><a id="int"></a>int()</dt>
<dd>

<p><code>int()</code> returns (at least for Perl v5.7.1 and up) another Math::BigInt, not a Perl scalar:</p>

<pre><code>$x = Math::BigInt-&gt;new(123);
$y = int($x);                           # 123 as a Math::BigInt
$x = Math::BigFloat-&gt;new(123.45);
$y = int($x);                           # 123 as a Math::BigFloat</code></pre>

<p>If you want a real Perl scalar, use <code>numify()</code>:</p>

<pre><code>$y = $x-&gt;numify();                      # 123 as a scalar</code></pre>

<p>This is seldom necessary, though, because this is done automatically, like when you access an array:</p>

<pre><code>$z = $array[$x];                        # does work automatically</code></pre>

</dd>
<dt id="Modifying-and-="><a class="permalink" href="./Math::BigInt.html#Modifying-and-=">#</a><a id="Modifying"></a><a id="Modifying-and"></a>Modifying and =</dt>
<dd>

<p>Beware of:</p>

<pre><code>$x = Math::BigFloat-&gt;new(5);
$y = $x;</code></pre>

<p>This makes a second reference to the <b>same</b> object and stores it in $y. Thus anything that modifies $x (except overloaded operators) also modifies $y, and vice versa. Or in other words, <code>=</code> is only safe if you modify your Math::BigInt objects only via overloaded math. As soon as you use a method call it breaks:</p>

<pre><code>$x-&gt;bmul(2);
print &quot;$x, $y\n&quot;;       # prints &#39;10, 10&#39;</code></pre>

<p>If you want a true copy of $x, use:</p>

<pre><code>$y = $x-&gt;copy();</code></pre>

<p>You can also chain the calls like this, this first makes a copy and then multiply it by 2:</p>

<pre><code>$y = $x-&gt;copy()-&gt;bmul(2);</code></pre>

<p>See also the documentation for overload.pm regarding <code>=</code>.</p>

</dd>
<dt id="Overloading-$x"><a class="permalink" href="./Math::BigInt.html#Overloading-$x">#</a><a id="Overloading"></a><a id="Overloading---x"></a>Overloading -$x</dt>
<dd>

<p>The following:</p>

<pre><code>$x = -$x;</code></pre>

<p>is slower than</p>

<pre><code>$x-&gt;bneg();</code></pre>

<p>since overload calls <code>sub($x,0,1);</code> instead of <code>neg($x)</code>. The first variant needs to preserve $x since it does not know that it later gets overwritten. This makes a copy of $x and takes O(N), but $x-&gt;bneg() is O(1).</p>

</dd>
<dt id="Mixing-different-object-types"><a class="permalink" href="./Math::BigInt.html#Mixing-different-object-types">#</a><a id="Mixing"></a>Mixing different object types</dt>
<dd>

<p>With overloaded operators, it is the first (dominating) operand that determines which method is called. Here are some examples showing what actually gets called in various cases.</p>

<pre><code>use Math::BigInt;
use Math::BigFloat;

$mbf  = Math::BigFloat-&gt;new(5);
$mbi2 = Math::BigInt-&gt;new(5);
$mbi  = Math::BigInt-&gt;new(2);
                                # what actually gets called:
$float = $mbf + $mbi;           # $mbf-&gt;badd($mbi)
$float = $mbf / $mbi;           # $mbf-&gt;bdiv($mbi)
$integer = $mbi + $mbf;         # $mbi-&gt;badd($mbf)
$integer = $mbi2 / $mbi;        # $mbi2-&gt;bdiv($mbi)
$integer = $mbi2 / $mbf;        # $mbi2-&gt;bdiv($mbf)</code></pre>

<p>For instance, Math::BigInt-&gt;bdiv() always returns a Math::BigInt, regardless of whether the second operant is a Math::BigFloat. To get a Math::BigFloat you either need to call the operation manually, make sure each operand already is a Math::BigFloat, or cast to that type via Math::BigFloat-&gt;new():</p>

<pre><code>$float = Math::BigFloat-&gt;new($mbi2) / $mbi;     # = 2.5</code></pre>

<p>Beware of casting the entire expression, as this would cast the result, at which point it is too late:</p>

<pre><code>$float = Math::BigFloat-&gt;new($mbi2 / $mbi);     # = 2</code></pre>

<p>Beware also of the order of more complicated expressions like:</p>

<pre><code>$integer = ($mbi2 + $mbi) / $mbf;               # int / float =&gt; int
$integer = $mbi2 / Math::BigFloat-&gt;new($mbi);   # ditto</code></pre>

<p>If in doubt, break the expression into simpler terms, or cast all operands to the desired resulting type.</p>

<p>Scalar values are a bit different, since:</p>

<pre><code>$float = 2 + $mbf;
$float = $mbf + 2;</code></pre>

<p>both result in the proper type due to the way the overloaded math works.</p>

<p>This section also applies to other overloaded math packages, like Math::String.</p>

<p>One solution to you problem might be autoupgrading|upgrading. See the pragmas <a href="bignum.html">bignum</a>, <a href="bigint.html">bigint</a> and <a href="bigrat.html">bigrat</a> for an easy way to do this.</p>

</dd>
</dl>

<h1 id="BUGS"><a class="permalink" href="./Math::BigInt.html#BUGS">#</a>BUGS</h1>

<p>Please report any bugs or feature requests to <code>bug-math-bigint at rt.cpan.org</code>, or through the web interface at <a href="https://rt.cpan.org/Ticket/Create.html?Queue=Math-BigInt">https://rt.cpan.org/Ticket/Create.html?Queue=Math-BigInt</a> (requires login). We will be notified, and then you&#39;ll automatically be notified of progress on your bug as I make changes.</p>

<h1 id="SUPPORT"><a class="permalink" href="./Math::BigInt.html#SUPPORT">#</a>SUPPORT</h1>

<p>You can find documentation for this module with the perldoc command.</p>

<pre><code class="plaintext">perldoc Math::BigInt</code></pre>

<p>You can also look for information at:</p>

<ul>

<li><p>RT: CPAN&#39;s request tracker</p>

<p><a href="https://rt.cpan.org/Public/Dist/Display.html?Name=Math-BigInt">https://rt.cpan.org/Public/Dist/Display.html?Name=Math-BigInt</a></p>

</li>
<li><p>AnnoCPAN: Annotated CPAN documentation</p>

<p><a href="http://annocpan.org/dist/Math-BigInt">http://annocpan.org/dist/Math-BigInt</a></p>

</li>
<li><p>CPAN Ratings</p>

<p><a href="https://cpanratings.perl.org/dist/Math-BigInt">https://cpanratings.perl.org/dist/Math-BigInt</a></p>

</li>
<li><p>MetaCPAN</p>

<p><a href="https://metacpan.org/release/Math-BigInt">https://metacpan.org/release/Math-BigInt</a></p>

</li>
<li><p>CPAN Testers Matrix</p>

<p><a href="http://matrix.cpantesters.org/?dist=Math-BigInt">http://matrix.cpantesters.org/?dist=Math-BigInt</a></p>

</li>
<li><p>The Bignum mailing list</p>

<ul>

<li><p>Post to mailing list</p>

<p><code>bignum at lists.scsys.co.uk</code></p>

</li>
<li><p>View mailing list</p>

<p><a href="http://lists.scsys.co.uk/pipermail/bignum/">http://lists.scsys.co.uk/pipermail/bignum/</a></p>

</li>
<li><p>Subscribe/Unsubscribe</p>

<p><a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/bignum">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/bignum</a></p>

</li>
</ul>

</li>
</ul>

<h1 id="LICENSE"><a class="permalink" href="./Math::BigInt.html#LICENSE">#</a>LICENSE</h1>

<p>This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="./Math::BigInt.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="./Math::BigFloat.html">Math::BigFloat</a> and <a href="./Math::BigRat.html">Math::BigRat</a> as well as the backends <a href="./Math::BigInt::FastCalc.html">Math::BigInt::FastCalc</a>, <a href="./Math::BigInt::GMP.html">Math::BigInt::GMP</a>, and <a href="./Math::BigInt::Pari.html">Math::BigInt::Pari</a>.</p>

<p>The pragmas <a href="bignum.html">bignum</a>, <a href="bigint.html">bigint</a> and <a href="bigrat.html">bigrat</a> also might be of interest because they solve the autoupgrading/downgrading issue, at least partly.</p>

<h1 id="AUTHORS"><a class="permalink" href="./Math::BigInt.html#AUTHORS">#</a>AUTHORS</h1>

<ul>

<li><p>Mark Biggar, overloaded interface by Ilya Zakharevich, 1996-2001.</p>

</li>
<li><p>Completely rewritten by Tels <a href="http://bloodgate.com">http://bloodgate.com</a>, 2001-2008.</p>

</li>
<li><p>Florian Ragwitz &lt;flora@cpan.org&gt;, 2010.</p>

</li>
<li><p>Peter John Acklam &lt;pjacklam@online.no&gt;, 2011-.</p>

</li>
</ul>

<p>Many people contributed in one or more ways to the final beast, see the file CREDITS for an (incomplete) list. If you miss your name, please drop me a mail. Thank you!</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
